Skip to content

Commit 9f19692

Browse files
author
Bob Hewett
committed
Merge pull request #97 from johngatti/master
Unit tests, integration tests and some fixes to code based on tests
2 parents 2f7d513 + b14c155 commit 9f19692

15 files changed

Lines changed: 973 additions & 32 deletions

File tree

mozu-java-sdk/src/main/java/com/mozu/client/MozuHttpClientPool.java renamed to mozu-java-sdk/src/main/java/com/mozu/api/utils/MozuHttpClientPool.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.mozu.client;
1+
package com.mozu.api.utils;
22

33
import java.io.IOException;
44
import java.util.concurrent.ArrayBlockingQueue;

mozu-java-sdk/src/main/java/com/mozu/client/MozuClientImpl.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.mozu.api.security.UserAuthenticator;
4848
import com.mozu.api.utils.HttpHelper;
4949
import com.mozu.api.utils.JsonUtils;
50+
import com.mozu.api.utils.MozuHttpClientPool;
5051

5152
public class MozuClientImpl<TResult> implements MozuClient<TResult> {
5253
private static final ObjectMapper mapper = JsonUtils.initObjectMapper();

mozu-java-toolkit/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ dependencies {
6969
compile ("org.springframework.batch:spring-batch-core:2.2.3.RELEASE");
7070
compile ("org.springframework.integration:spring-integration-core:3.0.2.RELEASE");
7171

72-
compile ("com.mozu:mozu-api-java:1.12.0") {
72+
compile ("com.mozu:mozu-api-java:1.13.0") {
7373
exclude group: 'mysql'
7474
exclude group: 'xerces'
7575
exclude group: 'berkeleydb'

mozu-java-toolkit/src/main/integrationtest/java/com/mozu/base/handlers/EntityHandlerTest.java renamed to mozu-java-toolkit/src/integrationtest/java/com/mozu/base/handlers/EntityHandlerIntegrationTest.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import java.util.ArrayList;
66
import java.util.List;
77

8-
import junit.framework.Assert;
98

10-
import org.apache.commons.lang3.StringUtils;
119
import org.junit.After;
1210
import org.junit.AfterClass;
1311
import org.junit.Before;
@@ -18,24 +16,18 @@
1816
import org.springframework.test.context.ContextConfiguration;
1917
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
2018

21-
import com.fasterxml.jackson.core.type.TypeReference;
2219
import com.mozu.api.ApiContext;
23-
import com.mozu.api.ApiException;
2420
import com.mozu.api.MozuApiContext;
2521
import com.mozu.api.contracts.mzdb.EntityList;
2622
import com.mozu.api.contracts.mzdb.IndexedProperty;
27-
import com.mozu.api.resources.platform.EntityListResource;
28-
import com.mozu.base.models.AppInfo;
2923
import com.mozu.base.models.EntityCollection;
3024
import com.mozu.base.models.EntityDataTypes;
3125
import com.mozu.base.models.EntityScope;
32-
import com.mozu.base.models.ExtensionParent;
3326
import com.mozu.base.models.Contact;
34-
import com.mozu.base.utils.ApplicationUtils;
3527

3628
@RunWith(SpringJUnit4ClassRunner.class)
3729
@ContextConfiguration(locations= {"file:src/main/resources/servlet-context.xml" })
38-
public class EntityHandlerTest {
30+
public class EntityHandlerIntegrationTest {
3931

4032
@Autowired
4133
EntitySchemaHandler entitySchemaHandler;

mozu-java-toolkit/src/main/integrationtest/java/com/mozu/base/handlers/ExtensionHandlerTest.java renamed to mozu-java-toolkit/src/integrationtest/java/com/mozu/base/handlers/ExtensionHandlerTest.java

File renamed without changes.

mozu-java-toolkit/src/main/integrationtest/java/com/mozu/base/models/Contact.java renamed to mozu-java-toolkit/src/integrationtest/java/com/mozu/base/models/Contact.java

File renamed without changes.

mozu-java-toolkit/src/main/java/com/mozu/base/handlers/EncryptDecryptHandler.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,7 @@ public class EncryptDecryptHandler {
2020
* @return an encrypted String
2121
*/
2222
public String encrypt( String value) {
23-
24-
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
25-
textEncryptor.setPassword(AppAuthenticator.getInstance().getAppAuthInfo().getSharedSecret());
26-
27-
return textEncryptor.encrypt(value);
23+
return encrypt(null, value);
2824
}
2925

3026
/**
@@ -34,9 +30,17 @@ public String encrypt( String value) {
3430
* @return an encrypted string.
3531
*/
3632
public String encrypt(String key, String value) {
33+
if (value==null) {
34+
throw new IllegalArgumentException("String to be encrypted required");
35+
}
3736

3837
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
39-
textEncryptor.setPassword(AppAuthenticator.getInstance().getAppAuthInfo().getSharedSecret()+key);
38+
39+
String sharedSecret = AppAuthenticator.getInstance().getAppAuthInfo().getSharedSecret();
40+
if (sharedSecret==null && key==null) {
41+
throw new IllegalArgumentException("Password key required");
42+
}
43+
textEncryptor.setPassword(sharedSecret+key);
4044

4145
return textEncryptor.encrypt(value);
4246
}
@@ -47,11 +51,7 @@ public String encrypt(String key, String value) {
4751
* @return the decrypted
4852
*/
4953
public String decrypt( String encryptedStr) {
50-
51-
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
52-
textEncryptor.setPassword(AppAuthenticator.getInstance().getAppAuthInfo().getSharedSecret());
53-
54-
return textEncryptor.decrypt(encryptedStr);
54+
return decrypt(null, encryptedStr);
5555
}
5656

5757
/**
@@ -61,6 +61,9 @@ public String decrypt( String encryptedStr) {
6161
* @return a string in clear text.
6262
*/
6363
public String decrypt(String key, String encryptedStr) {
64+
if (encryptedStr==null) {
65+
throw new IllegalArgumentException("String to be decrypted required");
66+
}
6467

6568
BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
6669
textEncryptor.setPassword(AppAuthenticator.getInstance().getAppAuthInfo().getSharedSecret()+key);

mozu-java-toolkit/src/main/java/com/mozu/base/handlers/EntityHandler.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package com.mozu.base.handlers;
22

33
import java.util.ArrayList;
4-
import java.util.List;
54

65
import org.apache.commons.lang3.StringUtils;
76
import org.slf4j.Logger;
87
import org.slf4j.LoggerFactory;
9-
import org.springframework.stereotype.Component;
108

119
import com.fasterxml.jackson.databind.JavaType;
1210
import com.fasterxml.jackson.databind.JsonNode;

mozu-java-toolkit/src/main/java/com/mozu/base/handlers/EntitySchemaHandler.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mozu.base.handlers;
22

3-
import java.util.ArrayList;
43
import java.util.List;
54

65
import org.apache.commons.lang.StringUtils;
@@ -53,8 +52,11 @@ public EntityList installSchema(ApiContext apiContext, EntityList entityList, En
5352
if (StringUtils.isEmpty(entityList.getNameSpace())) entityList.setNameSpace(appInfo.getNameSpace());
5453

5554
String entityFqn = getEntityListNameFQN(entityList.getName(), entityList.getNameSpace());
56-
if (idProperty == null) entityList.setUseSystemAssignedId(true);
57-
else entityList.setIdProperty(idProperty);
55+
if (idProperty == null) {
56+
entityList.setUseSystemAssignedId(true);
57+
} else {
58+
entityList.setIdProperty(idProperty);
59+
}
5860

5961
if (indexedProperties != null) {
6062
entityList.setIndexA(indexedProperties.size() >=1 ? indexedProperties.get(0) : null);

mozu-java-toolkit/src/main/resources/mozu-base.xml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,4 @@
2020
</mvc:interceptor>
2121
</mvc:interceptors>
2222

23-
<beans:bean id="cacheManagerImpl" name="cacheManagerImpl"
24-
class="com.mozu.api.cache.impl.CacheManagerImpl" init-method="startCache"
25-
destroy-method="stopCache" lazy-init="false">
26-
</beans:bean>
27-
2823
</beans:beans>

0 commit comments

Comments
 (0)