Skip to content

Commit 294c22e

Browse files
committed
change validation method in tests
1 parent 2fd2173 commit 294c22e

1 file changed

Lines changed: 26 additions & 21 deletions

File tree

NetLicensingClient/src/test/java/com/labs64/netlicensing/service/LicenseeServiceTest.java

Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ public class LicenseeServiceTest extends BaseServiceTest {
5353
private static final String LICENSEE_CUSTOM_PROPERTY = "CustomProperty";
5454
private static final String LICENSEE_DELETING_PROPERTY = "toBeDeleted";
5555

56+
final String productNumber = "P001-TEST";
57+
final String licenseeNumber = "L001-TEST";
58+
5659
// *** NLIC Tests ***
5760

5861
private static Context context;
@@ -68,25 +71,25 @@ public static void setup() {
6871
@Test
6972
public void testCreate() throws Exception {
7073
final Licensee newLicensee = new LicenseeImpl();
71-
newLicensee.setNumber("L001-TEST");
74+
newLicensee.setNumber(licenseeNumber);
7275
newLicensee.setActive(false);
7376

74-
final Licensee createdLicensee = LicenseeService.create(context, "P001-TEST", newLicensee);
77+
final Licensee createdLicensee = LicenseeService.create(context, productNumber, newLicensee);
7578

7679
assertNotNull(createdLicensee);
77-
assertEquals("L001-TEST", createdLicensee.getNumber());
80+
assertEquals(licenseeNumber, createdLicensee.getNumber());
7881
assertEquals(false, createdLicensee.getActive());
79-
assertEquals("P001-TEST", createdLicensee.getProduct().getNumber());
82+
assertEquals(productNumber, createdLicensee.getProduct().getNumber());
8083
}
8184

8285
@Test
8386
public void testCreateEmpty() throws Exception {
8487
final Licensee newLicensee = new LicenseeImpl();
85-
final Licensee createdLicensee = LicenseeService.create(context, "P001-TEST", newLicensee);
88+
final Licensee createdLicensee = LicenseeService.create(context, productNumber, newLicensee);
8689

8790
assertNotNull(createdLicensee);
8891
assertEquals(true, createdLicensee.getActive());
89-
assertEquals("P001-TEST", createdLicensee.getProduct().getNumber());
92+
assertEquals(productNumber, createdLicensee.getProduct().getNumber());
9093
}
9194

9295
@Test
@@ -98,12 +101,12 @@ public void testCreateWithoutProductNumber() throws Exception {
98101

99102
@Test
100103
public void testGet() throws Exception {
101-
final Licensee licensee = LicenseeService.get(context, "L001-TEST");
104+
final Licensee licensee = LicenseeService.get(context, licenseeNumber);
102105

103106
assertNotNull(licensee);
104-
assertEquals("L001-TEST", licensee.getNumber());
107+
assertEquals(licenseeNumber, licensee.getNumber());
105108
assertEquals(true, licensee.getActive());
106-
assertEquals("P001-TEST", licensee.getProduct().getNumber());
109+
assertEquals(productNumber, licensee.getProduct().getNumber());
107110
assertEquals("Custom property value", licensee.getLicenseeProperties().get(LICENSEE_CUSTOM_PROPERTY));
108111
}
109112

@@ -114,9 +117,9 @@ public void testList() throws Exception {
114117
assertNotNull(licensees);
115118
assertTrue(licensees.hasContent());
116119
assertEquals(3, licensees.getItemsNumber());
117-
assertEquals("L001-TEST", licensees.getContent().get(0).getNumber());
120+
assertEquals(licenseeNumber, licensees.getContent().get(0).getNumber());
118121
assertEquals(true, licensees.getContent().get(1).getActive());
119-
assertEquals("P001-TEST", licensees.getContent().get(2).getProduct().getNumber());
122+
assertEquals(productNumber, licensees.getContent().get(2).getProduct().getNumber());
120123
}
121124

122125
@Test
@@ -127,19 +130,19 @@ public void testUpdate() throws Exception {
127130
licensee.addProperty(LICENSEE_CUSTOM_PROPERTY, "New property value");
128131
licensee.addProperty(LICENSEE_DELETING_PROPERTY, "");
129132

130-
final Licensee updatedLicensee = LicenseeService.update(context, "L001-TEST", licensee);
133+
final Licensee updatedLicensee = LicenseeService.update(context, licenseeNumber, licensee);
131134

132135
assertNotNull(updatedLicensee);
133136
assertEquals("L002-TEST", updatedLicensee.getNumber());
134137
assertEquals(true, updatedLicensee.getActive());
135-
assertEquals("P001-TEST", updatedLicensee.getProduct().getNumber());
138+
assertEquals(productNumber, updatedLicensee.getProduct().getNumber());
136139
assertEquals("New property value", updatedLicensee.getLicenseeProperties().get(LICENSEE_CUSTOM_PROPERTY));
137140
assertNull(updatedLicensee.getLicenseeProperties().get(LICENSEE_DELETING_PROPERTY));
138141
}
139142

140143
@Test
141144
public void testDelete() throws Exception {
142-
LicenseeService.delete(context, "L001-TEST", true);
145+
LicenseeService.delete(context, licenseeNumber, true);
143146

144147
thrown.expect(ServiceException.class);
145148
thrown.expectMessage("NotFoundException: Requested licensee does not exist");
@@ -148,9 +151,11 @@ public void testDelete() throws Exception {
148151

149152
@Test
150153
public void testValidate() throws Exception {
154+
151155
final ValidationParameters validationParameters = new ValidationParameters();
152-
final ValidationResult result = LicenseeService.validate(context, "L001-TEST", "P001-TEST", "Test Licensee",
153-
validationParameters);
156+
validationParameters.setLicenseeName("Test Licensee");
157+
validationParameters.setProductNumber(productNumber);
158+
final ValidationResult result = LicenseeService.validate(context, licenseeNumber, validationParameters);
154159

155160
assertNotNull(result);
156161

@@ -163,11 +168,11 @@ public void testValidate() throws Exception {
163168
assertEquals(
164169
"true",
165170
validation.getProperties().get("LIST1").getProperties()
166-
.get(Constants.LicensingModel.VALID).getValue());
171+
.get(Constants.LicensingModel.VALID).getValue());
167172
assertEquals(
168173
"green",
169174
validation.getProperties().get("LIST2").getProperties()
170-
.get(Constants.LicensingModel.Rental.EXPIRATION_WARNING_LEVEL).getValue());
175+
.get(Constants.LicensingModel.Rental.EXPIRATION_WARNING_LEVEL).getValue());
171176
}
172177

173178
// *** NLIC test mock resource ***
@@ -197,12 +202,12 @@ public Response create(final MultivaluedMap<String, String> formParams) {
197202

198203
@Override
199204
public Response delete(final String licenseeNumber, final UriInfo uriInfo) {
200-
return delete(licenseeNumber, "L001-TEST", uriInfo.getQueryParameters());
205+
return delete(licenseeNumber, licenseeNumber, uriInfo.getQueryParameters());
201206
}
202207

203208
/**
204209
* Mock for "validate licensee" service.
205-
*
210+
*
206211
* @param licenseeNumber
207212
* licensee number
208213
* @param productNumber
@@ -217,7 +222,7 @@ public Response validateLicensee(@PathParam("licenseeNumber") final String licen
217222
@QueryParam("productNumber") final String productNumber,
218223
@QueryParam("licenseeName") final String licenseeName) {
219224

220-
if (!"P001-TEST".equals(productNumber)) {
225+
if (!productNumber.equals(productNumber)) {
221226
return unexpectedValueErrorResponse("productNumber");
222227
}
223228
if (!"Test Licensee".equals(licenseeName)) {

0 commit comments

Comments
 (0)