Skip to content

Commit d664e02

Browse files
committed
Remove internal items from TokenType, bump min java to 8.
1 parent 4c3bfb2 commit d664e02

File tree

7 files changed

+24
-89
lines changed

7 files changed

+24
-89
lines changed

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/Token.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
import java.util.Date;
1616
import java.util.Map;
1717

18-
import com.labs64.netlicensing.domain.vo.TokenType;
18+
import com.labs64.netlicensing.domain.vo.ITokenType;
1919

2020
/**
2121
* Token entity used internally by NetLicensing.
@@ -32,9 +32,9 @@ public interface Token extends BaseEntity {
3232

3333
void setExpirationTime(Date expirationTime);
3434

35-
TokenType getTokenType();
35+
ITokenType getTokenType();
3636

37-
void setTokenType(TokenType tokenType);
37+
void setTokenType(ITokenType tokenType);
3838

3939
// Methods for working with custom properties
4040

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/entity/impl/TokenImpl.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
import com.labs64.netlicensing.domain.Constants;
2222
import com.labs64.netlicensing.domain.entity.Token;
23-
import com.labs64.netlicensing.domain.vo.TokenType;
23+
import com.labs64.netlicensing.domain.vo.ITokenType;
2424

2525
/**
2626
* Default implementation of {@link com.labs64.netlicensing.domain.entity.Token}.
@@ -33,7 +33,7 @@ public class TokenImpl extends BaseEntityImpl implements Token {
3333

3434
private Date expirationTime;
3535

36-
private TokenType tokenType;
36+
private ITokenType tokenType;
3737

3838
/**
3939
* @see BaseEntityImpl#getReservedProps()
@@ -74,12 +74,12 @@ public void setExpirationTime(final Date expirationTime) {
7474
}
7575

7676
@Override
77-
public TokenType getTokenType() {
77+
public ITokenType getTokenType() {
7878
return tokenType;
7979
}
8080

8181
@Override
82-
public void setTokenType(final TokenType tokenType) {
82+
public void setTokenType(final ITokenType tokenType) {
8383
this.tokenType = tokenType;
8484
}
8585

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.labs64.netlicensing.domain.vo;
2+
3+
public interface ITokenType {
4+
5+
String name();
6+
7+
}

NetLicensingClient/src/main/java/com/labs64/netlicensing/domain/vo/TokenType.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,15 @@
1515
/**
1616
* This enum defines available token types.
1717
*/
18-
public enum TokenType {
18+
public enum TokenType implements ITokenType {
1919

2020
DEFAULT,
2121

2222
APIKEY,
2323

24-
REGISTRATION,
25-
26-
PASSWORDRESET,
27-
2824
SHOP;
2925

30-
public static TokenType parseString(final String token) {
26+
public static ITokenType parseString(final String token) {
3127
if (token != null) {
3228
for (final TokenType tokenType : TokenType.values()) {
3329
if (token.equalsIgnoreCase(tokenType.name())) {

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

Lines changed: 6 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@
1212
*/
1313
package com.labs64.netlicensing.service;
1414

15-
import static org.junit.Assert.assertEquals;
16-
import static org.junit.Assert.assertNotNull;
17-
import static org.junit.Assert.assertNull;
18-
import static org.junit.Assert.assertTrue;
19-
2015
import java.util.HashMap;
2116
import java.util.Map;
2217
import java.util.UUID;
@@ -40,6 +35,11 @@
4035
import com.labs64.netlicensing.exception.ServiceException;
4136
import com.labs64.netlicensing.util.DateUtils;
4237

38+
import static org.junit.Assert.assertEquals;
39+
import static org.junit.Assert.assertNotNull;
40+
import static org.junit.Assert.assertNull;
41+
import static org.junit.Assert.assertTrue;
42+
4343
/**
4444
* Integration tests for {@link TokenService}.
4545
*/
@@ -84,41 +84,6 @@ public void testCreateEmptyApiKeyToken() throws Exception {
8484
assertEquals("VDEMO", createdToken.getVendorNumber());
8585
}
8686

87-
@Test
88-
public void testCreateEmptyRegistrationToken() throws Exception {
89-
final TokenImpl newToken = new TokenImpl();
90-
newToken.setTokenType(TokenType.REGISTRATION);
91-
newToken.addProperty(Constants.Token.TOKEN_PROP_EMAIL, "test@test.com");
92-
93-
final Token createdToken = TokenService.create(context, newToken);
94-
95-
assertNotNull(createdToken);
96-
assertNotNull(createdToken.getNumber());
97-
assertEquals(true, createdToken.getActive());
98-
assertNotNull(createdToken.getExpirationTime());
99-
assertEquals(TokenType.REGISTRATION, createdToken.getTokenType());
100-
assertEquals("VDEMO", createdToken.getVendorNumber());
101-
assertEquals("test@test.com", createdToken.getProperties().get(Constants.Token.TOKEN_PROP_EMAIL));
102-
}
103-
104-
@Test
105-
public void testCreateEmptyPasswordResetToken() throws Exception {
106-
final TokenImpl newToken = new TokenImpl();
107-
newToken.setTokenType(TokenType.PASSWORDRESET);
108-
newToken.setVendorNumber("VDEMO2");
109-
newToken.addProperty(Constants.Token.TOKEN_PROP_EMAIL, "test@test.com");
110-
111-
final Token createdToken = TokenService.create(context, newToken);
112-
113-
assertNotNull(createdToken);
114-
assertNotNull(createdToken.getNumber());
115-
assertEquals(true, createdToken.getActive());
116-
assertNotNull(createdToken.getExpirationTime());
117-
assertEquals(TokenType.PASSWORDRESET, createdToken.getTokenType());
118-
assertEquals("VDEMO2", createdToken.getVendorNumber());
119-
assertEquals("test@test.com", createdToken.getProperties().get(Constants.Token.TOKEN_PROP_EMAIL));
120-
}
121-
12287
@Test
12388
public void testCreateEmptyShopToken() throws Exception {
12489
final TokenImpl newToken = new TokenImpl();
@@ -137,26 +102,6 @@ public void testCreateEmptyShopToken() throws Exception {
137102
assertEquals("VDEMO", createdToken.getVendorNumber());
138103
}
139104

140-
@Test
141-
public void testCreateRegistrationTokenWithoutEmail() throws Exception {
142-
final TokenImpl newToken = new TokenImpl();
143-
newToken.setTokenType(TokenType.REGISTRATION);
144-
145-
thrown.expect(ServiceException.class);
146-
thrown.expectMessage("MalformedRequestException: Malformed token request, TokenValidation: Property 'email' not found");
147-
TokenService.create(context, newToken);
148-
}
149-
150-
@Test
151-
public void testCreatePasswordResetTokenWithoutEmailAndVendorNumber() throws Exception {
152-
final TokenImpl newToken = new TokenImpl();
153-
newToken.setTokenType(TokenType.PASSWORDRESET);
154-
155-
thrown.expect(ServiceException.class);
156-
thrown.expectMessage("MalformedRequestException: Malformed token request, TokenValidation: Property 'email' not found, TokenValidation: Property 'targetVendorNumber' not found");
157-
TokenService.create(context, newToken);
158-
}
159-
160105
@Test
161106
public void testCreateShopTokenWithoutLicenseeNumber() throws Exception {
162107
final TokenImpl newToken = new TokenImpl();
@@ -193,7 +138,7 @@ public void testList() throws Exception {
193138
assertEquals("08b66094-a5c4-4c93-be71-567e982d9428", tokens.getContent().get(0).getNumber());
194139
assertEquals(DateUtils.parseDate("2014-07-22T23:07:46.742Z").getTime(), tokens.getContent().get(1)
195140
.getExpirationTime());
196-
assertEquals(TokenType.REGISTRATION, tokens.getContent().get(2).getTokenType());
141+
assertEquals(TokenType.APIKEY, tokens.getContent().get(2).getTokenType());
197142
}
198143

199144
@Test
@@ -222,18 +167,6 @@ public TokenServiceResource() {
222167
@Override
223168
public Response create(final MultivaluedMap<String, String> formParams) {
224169
final String targetTokenType = formParams.getFirst(Constants.Token.TOKEN_TYPE);
225-
if (TokenType.REGISTRATION.name().equals(targetTokenType)
226-
&& !formParams.containsKey(Constants.Token.TOKEN_PROP_EMAIL)) {
227-
return errorResponse("MalformedRequestException", "Malformed token request",
228-
"TokenValidation", "Property 'email' not found");
229-
}
230-
if (TokenType.PASSWORDRESET.name().equals(targetTokenType)
231-
&& !formParams.containsKey(Constants.Token.TOKEN_PROP_EMAIL)
232-
&& !formParams.containsKey(Constants.Token.TOKEN_PROP_VENDORNUMBER)) {
233-
return errorResponse("MalformedRequestException", "Malformed token request",
234-
"TokenValidation", "Property 'email' not found",
235-
"TokenValidation", "Property 'targetVendorNumber' not found");
236-
}
237170
if (TokenType.SHOP.name().equals(targetTokenType)
238171
&& !formParams.containsKey(Constants.Licensee.LICENSEE_NUMBER)) {
239172
return errorResponse("MalformedRequestException", "Malformed token request",

NetLicensingClient/src/test/resources/mock/netlicensing-token-list.xml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@
2525
<property name="number">0c924950-de52-4581-b2dc-5031fa04ef29</property>
2626
<property name="active">true</property>
2727
<property name="expirationTime">2014-08-06T13:18:05.982Z</property>
28-
<property name="tokenType">REGISTRATION</property>
29-
<property name="email">test@test.com</property>
28+
<property name="tokenType">APIKEY</property>
3029
<property name="vendorNumber">VDEMO</property>
3130
</item>
3231
</items>

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
<project.title>${project.name}</project.title>
6868
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
6969

70-
<java.version>1.7</java.version>
70+
<java.version>1.8</java.version>
7171
<maven.version>3.0.5</maven.version>
7272

7373
<repo.releases.url>OVERRIDE_REPO_URL</repo.releases.url>

0 commit comments

Comments
 (0)