|
38 | 38 | @FixMethodOrder(MethodSorters.NAME_ASCENDING) |
39 | 39 | public class NaturalLanguageClassifierIT extends WatsonServiceTest { |
40 | 40 |
|
41 | | - /** The classifier id. */ |
42 | | - private static String classifierId = null; |
43 | | - private String preCreatedClassifierId; |
44 | | - |
45 | | - /** The service. */ |
46 | | - private NaturalLanguageClassifier service; |
47 | | - |
48 | | - /* |
49 | | - * (non-Javadoc) |
50 | | - * |
51 | | - * @see com.ibm.watson.developer_cloud.WatsonServiceTest#setUp() |
52 | | - */ |
53 | | - @Override |
54 | | - @Before |
55 | | - public void setUp() throws Exception { |
56 | | - super.setUp(); |
57 | | - String username = getProperty("natural_language_classifier.username"); |
58 | | - String password = getProperty("natural_language_classifier.password"); |
59 | | - |
60 | | - Assume.assumeFalse("config.properties doesn't have valid credentials.", |
61 | | - (username == null) || username.equals(PLACEHOLDER)); |
62 | | - |
63 | | - service = new NaturalLanguageClassifier(); |
64 | | - service.setDefaultHeaders(getDefaultHeaders()); |
65 | | - service.setUsernameAndPassword(username, password); |
66 | | - service.setEndPoint(getProperty("natural_language_classifier.url")); |
67 | | - |
68 | | - preCreatedClassifierId = getProperty("natural_language_classifier.classifier_id"); |
69 | | - } |
70 | | - |
71 | | - /** |
72 | | - * Creates the classifier. |
73 | | - * |
74 | | - * @throws Exception the exception |
75 | | - */ |
76 | | - @Test |
77 | | - public void Acreate() throws Exception { |
78 | | - final File trainingData = new File("src/test/resources/natural_language_classifier/weather_data_train.csv"); |
79 | | - final String classifierName = "devexp-available"; |
80 | | - |
81 | | - Classifier classifier = service.createClassifier(classifierName, "en", trainingData).execute(); |
82 | | - |
83 | | - try { |
84 | | - assertNotNull(classifier); |
85 | | - assertEquals(Status.TRAINING, classifier.getStatus()); |
86 | | - assertEquals(classifierName, classifier.getName()); |
87 | | - } finally { |
88 | | - classifierId = classifier.getId(); |
89 | | - } |
90 | | - |
91 | | - } |
92 | | - |
93 | | - /** |
94 | | - * Test get classifier. |
95 | | - */ |
96 | | - @Test |
97 | | - public void BgetClassifier() { |
98 | | - final Classifier classifier; |
99 | | - |
100 | | - try { |
101 | | - classifier = service.getClassifier(classifierId).execute(); |
102 | | - } catch (NotFoundException e) { |
103 | | - // #324: Classifiers may be empty, because of other tests interfering. |
104 | | - // The build should not fail here, because this is out of our control. |
105 | | - throw new AssumptionViolatedException(e.getMessage(), e); |
106 | | - } |
107 | | - assertNotNull(classifier); |
108 | | - assertEquals(classifierId, classifier.getId()); |
109 | | - assertEquals(Classifier.Status.TRAINING, classifier.getStatus()); |
110 | | - } |
111 | | - |
112 | | - /** |
113 | | - * Test get classifiers. |
114 | | - */ |
115 | | - @Test |
116 | | - public void CgetClassifiers() { |
117 | | - final Classifiers classifiers = service.getClassifiers().execute(); |
118 | | - assertNotNull(classifiers); |
119 | | - |
120 | | - // #324: Classifiers may be empty, because of other tests interfering. |
121 | | - // The build should not fail here, because this is out of our control. |
122 | | - Assume.assumeFalse(classifiers.getClassifiers().isEmpty()); |
123 | | - } |
124 | | - |
125 | | - /** |
126 | | - * Test classify. Use the pre created classifier to avoid waiting for availability |
127 | | - */ |
128 | | - @Test |
129 | | - public void Dclassify() { |
130 | | - Classification classification = null; |
131 | | - |
132 | | - try { |
133 | | - classification = service.classify(preCreatedClassifierId, "is it hot outside?").execute(); |
134 | | - } catch (NotFoundException e) { |
135 | | - // #324: Classifiers may be empty, because of other tests interfering. |
136 | | - // The build should not fail here, because this is out of our control. |
137 | | - throw new AssumptionViolatedException(e.getMessage(), e); |
138 | | - } |
139 | | - |
140 | | - assertNotNull(classification); |
141 | | - assertEquals("temperature", classification.getTopClass()); |
142 | | - } |
143 | | - |
144 | | - /** |
145 | | - * Test delete classifier. Do not delete the pre created classifier. We need it for classify |
146 | | - */ |
147 | | - @Test |
148 | | - public void Edelete() { |
149 | | - List<Classifier> classifiers = service.getClassifiers().execute().getClassifiers(); |
150 | | - |
151 | | - for (Classifier classifier : classifiers) { |
152 | | - if (!classifier.getId().equals(preCreatedClassifierId)) { |
153 | | - service.deleteClassifier(classifier.getId()).execute(); |
154 | | - } |
155 | | - } |
156 | | - } |
| 41 | + /** The classifier id. */ |
| 42 | + private static String classifierId = null; |
| 43 | + private String preCreatedClassifierId; |
| 44 | + |
| 45 | + /** The service. */ |
| 46 | + private NaturalLanguageClassifier service; |
| 47 | + |
| 48 | + /* |
| 49 | + * (non-Javadoc) |
| 50 | + * |
| 51 | + * @see com.ibm.watson.developer_cloud.WatsonServiceTest#setUp() |
| 52 | + */ |
| 53 | + @Override |
| 54 | + @Before |
| 55 | + public void setUp() throws Exception { |
| 56 | + super.setUp(); |
| 57 | + String username = getProperty("natural_language_classifier.username"); |
| 58 | + String password = getProperty("natural_language_classifier.password"); |
| 59 | + |
| 60 | + Assume.assumeFalse("config.properties doesn't have valid credentials.", |
| 61 | + (username == null) || username.equals(PLACEHOLDER)); |
| 62 | + |
| 63 | + service = new NaturalLanguageClassifier(); |
| 64 | + service.setDefaultHeaders(getDefaultHeaders()); |
| 65 | + service.setUsernameAndPassword(username, password); |
| 66 | + service.setEndPoint(getProperty("natural_language_classifier.url")); |
| 67 | + |
| 68 | + preCreatedClassifierId = getProperty("natural_language_classifier.classifier_id"); |
| 69 | + } |
| 70 | + |
| 71 | + /** |
| 72 | + * Creates the classifier. |
| 73 | + * |
| 74 | + * @throws Exception the exception |
| 75 | + */ |
| 76 | + @Test |
| 77 | + public void Acreate() throws Exception { |
| 78 | + final File trainingData = new File("src/test/resources/natural_language_classifier/weather_data_train.csv"); |
| 79 | + final String classifierName = "devexp-available"; |
| 80 | + |
| 81 | + Classifier classifier = service.createClassifier(classifierName, "en", trainingData).execute(); |
| 82 | + |
| 83 | + try { |
| 84 | + assertNotNull(classifier); |
| 85 | + assertEquals(Status.TRAINING, classifier.getStatus()); |
| 86 | + assertEquals(classifierName, classifier.getName()); |
| 87 | + } finally { |
| 88 | + classifierId = classifier.getId(); |
| 89 | + } |
| 90 | + |
| 91 | + } |
| 92 | + |
| 93 | + /** |
| 94 | + * Test get classifier. |
| 95 | + */ |
| 96 | + @Test |
| 97 | + public void BgetClassifier() { |
| 98 | + final Classifier classifier; |
| 99 | + |
| 100 | + try { |
| 101 | + classifier = service.getClassifier(classifierId).execute(); |
| 102 | + } catch (NotFoundException e) { |
| 103 | + // #324: Classifiers may be empty, because of other tests interfering. |
| 104 | + // The build should not fail here, because this is out of our control. |
| 105 | + throw new AssumptionViolatedException(e.getMessage(), e); |
| 106 | + } |
| 107 | + assertNotNull(classifier); |
| 108 | + assertEquals(classifierId, classifier.getId()); |
| 109 | + assertEquals(Classifier.Status.TRAINING, classifier.getStatus()); |
| 110 | + } |
| 111 | + |
| 112 | + /** |
| 113 | + * Test get classifiers. |
| 114 | + */ |
| 115 | + @Test |
| 116 | + public void CgetClassifiers() { |
| 117 | + final Classifiers classifiers = service.getClassifiers().execute(); |
| 118 | + assertNotNull(classifiers); |
| 119 | + |
| 120 | + // #324: Classifiers may be empty, because of other tests interfering. |
| 121 | + // The build should not fail here, because this is out of our control. |
| 122 | + Assume.assumeFalse(classifiers.getClassifiers().isEmpty()); |
| 123 | + } |
| 124 | + |
| 125 | + /** |
| 126 | + * Test classify. Use the pre created classifier to avoid waiting for availability |
| 127 | + */ |
| 128 | + @Test |
| 129 | + public void Dclassify() { |
| 130 | + Classification classification = null; |
| 131 | + |
| 132 | + try { |
| 133 | + classification = service.classify(preCreatedClassifierId, "is it hot outside?").execute(); |
| 134 | + } catch (NotFoundException e) { |
| 135 | + // #324: Classifiers may be empty, because of other tests interfering. |
| 136 | + // The build should not fail here, because this is out of our control. |
| 137 | + throw new AssumptionViolatedException(e.getMessage(), e); |
| 138 | + } |
| 139 | + |
| 140 | + assertNotNull(classification); |
| 141 | + assertEquals("temperature", classification.getTopClass()); |
| 142 | + } |
| 143 | + |
| 144 | + /** |
| 145 | + * Test delete classifier. Do not delete the pre created classifier. We need it for classify |
| 146 | + */ |
| 147 | + @Test |
| 148 | + public void Edelete() { |
| 149 | + List<Classifier> classifiers = service.getClassifiers().execute().getClassifiers(); |
| 150 | + |
| 151 | + for (Classifier classifier : classifiers) { |
| 152 | + if (!classifier.getId().equals(preCreatedClassifierId)) { |
| 153 | + service.deleteClassifier(classifier.getId()).execute(); |
| 154 | + } |
| 155 | + } |
| 156 | + } |
157 | 157 |
|
158 | 158 | } |
0 commit comments