Skip to content

Commit 8401d2c

Browse files
author
eugenp
committed
cleaning up the marshallers; integration testing in maven properly configured
1 parent cf47a29 commit 8401d2c

7 files changed

Lines changed: 237 additions & 122 deletions

File tree

‎sec/eclipse/INTEGRATION-SINGLE.launch‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
22
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig">
33
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
4-
<listEntry value="/rest-sec/src/test/java/org/rest/sec/client/template/test/scenario/SecurityScenariosOverRestLiveTest.java"/>
4+
<listEntry value="/rest-sec/src/test/java/org/rest/sec/client/template/test/UserLogicClientRestIntegrationTest.java"/>
55
</listAttribute>
66
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
77
<listEntry value="1"/>
@@ -14,7 +14,7 @@
1414
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/>
1515
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/>
1616
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
17-
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.sec.client.template.test.scenario.SecurityScenariosOverRestLiveTest"/>
17+
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="org.rest.sec.client.template.test.UserLogicClientRestIntegrationTest"/>
1818
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="rest-sec"/>
1919
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/>
2020
</launchConfiguration>

‎sec/pom.xml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@
165165
<configuration>
166166
<excludes>
167167
<exclude>**/*RestIntegrationTest.java</exclude>
168+
<exclude>**/*RestLiveTest.java</exclude>
168169
</excludes>
169170
<systemPropertyVariables>
170171
<persistenceTarget>h2</persistenceTarget>
@@ -344,6 +345,7 @@
344345
</excludes>
345346
<includes>
346347
<include>**/*RestIntegrationTest.java</include>
348+
<include>**/*RestLiveTest.java</include>
347349
</includes>
348350
<systemPropertyVariables>
349351
<spring.profiles.active>client,mime_json</spring.profiles.active> <!-- should be removed -->
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package org.rest.sec.client.marshall;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import org.rest.common.client.marshall.IMarshaller;
7+
import org.rest.sec.model.Principal;
8+
import org.rest.sec.model.Privilege;
9+
import org.rest.sec.model.Role;
10+
import org.rest.sec.model.dto.User;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
import org.springframework.context.annotation.Profile;
14+
import org.springframework.http.MediaType;
15+
import org.springframework.stereotype.Component;
16+
17+
import com.fasterxml.jackson.core.JsonParseException;
18+
import com.fasterxml.jackson.core.type.TypeReference;
19+
import com.fasterxml.jackson.databind.JsonMappingException;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import com.google.common.base.Preconditions;
22+
23+
@Component
24+
@Profile("production")
25+
public final class ProdJacksonMarshaller implements IMarshaller {
26+
private final Logger logger = LoggerFactory.getLogger(ProdJacksonMarshaller.class);
27+
28+
private final ObjectMapper objectMapper;
29+
30+
public ProdJacksonMarshaller() {
31+
super();
32+
33+
objectMapper = new ObjectMapper();
34+
}
35+
36+
// API
37+
38+
@Override
39+
public final <T> String encode(final T entity) {
40+
Preconditions.checkNotNull(entity);
41+
String entityAsJSON = null;
42+
try {
43+
entityAsJSON = objectMapper.writeValueAsString(entity);
44+
} catch (final JsonParseException parseEx) {
45+
logger.error("", parseEx);
46+
} catch (final JsonMappingException mappingEx) {
47+
logger.error("", mappingEx);
48+
} catch (final IOException ioEx) {
49+
logger.error("", ioEx);
50+
}
51+
52+
return entityAsJSON;
53+
}
54+
55+
@Override
56+
public final <T> T decode(final String entityAsString, final Class<T> clazz) {
57+
Preconditions.checkNotNull(entityAsString);
58+
59+
T entity = null;
60+
try {
61+
entity = objectMapper.readValue(entityAsString, clazz);
62+
} catch (final JsonParseException parseEx) {
63+
logger.error("", parseEx);
64+
} catch (final JsonMappingException mappingEx) {
65+
logger.error("", mappingEx);
66+
} catch (final IOException ioEx) {
67+
logger.error("", ioEx);
68+
}
69+
70+
return entity;
71+
}
72+
73+
@SuppressWarnings("unchecked")
74+
@Override
75+
public final <T> List<T> decodeList(final String entitiesAsString, final Class<T> clazz) {
76+
Preconditions.checkNotNull(entitiesAsString);
77+
78+
List<T> entities = null;
79+
try {
80+
if (clazz.equals(Role.class)) {
81+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Role>>() {
82+
// ...
83+
});
84+
} else if (clazz.equals(Privilege.class)) {
85+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Privilege>>() {
86+
// ...
87+
});
88+
} else if (clazz.equals(User.class)) {
89+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<User>>() {
90+
// ...
91+
});
92+
} else if (clazz.equals(Principal.class)) {
93+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Principal>>() {
94+
// ...
95+
});
96+
} else {
97+
entities = objectMapper.readValue(entitiesAsString, List.class);
98+
}
99+
} catch (final JsonParseException parseEx) {
100+
logger.error("", parseEx);
101+
} catch (final JsonMappingException mappingEx) {
102+
logger.error("", mappingEx);
103+
} catch (final IOException ioEx) {
104+
logger.error("", ioEx);
105+
}
106+
107+
return entities;
108+
}
109+
110+
@Override
111+
public final String getMime() {
112+
return MediaType.APPLICATION_JSON.toString();
113+
}
114+
115+
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
spring.profiles.active=production,mime_xml
2-
# mime_json
3-
# mime_xml
1+
spring.profiles.active=production
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
spring.profiles.active=production,mime_json
1+
spring.profiles.active=production

sec/src/main/java/org/rest/sec/client/marshall/JacksonMarshaller.java renamed to sec/src/test/java/org/rest/sec/client/marshall/JacksonMarshaller.java

Lines changed: 115 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,115 +1,115 @@
1-
package org.rest.sec.client.marshall;
2-
3-
import java.io.IOException;
4-
import java.util.List;
5-
6-
import org.rest.common.client.marshall.IMarshaller;
7-
import org.rest.sec.model.Principal;
8-
import org.rest.sec.model.Privilege;
9-
import org.rest.sec.model.Role;
10-
import org.rest.sec.model.dto.User;
11-
import org.slf4j.Logger;
12-
import org.slf4j.LoggerFactory;
13-
import org.springframework.context.annotation.Profile;
14-
import org.springframework.http.MediaType;
15-
import org.springframework.stereotype.Component;
16-
17-
import com.fasterxml.jackson.core.JsonParseException;
18-
import com.fasterxml.jackson.core.type.TypeReference;
19-
import com.fasterxml.jackson.databind.JsonMappingException;
20-
import com.fasterxml.jackson.databind.ObjectMapper;
21-
import com.google.common.base.Preconditions;
22-
23-
@Component("jacksonMarshaller")
24-
@Profile("mime_json")
25-
public final class JacksonMarshaller implements IMarshaller {
26-
private final Logger logger = LoggerFactory.getLogger(JacksonMarshaller.class);
27-
28-
private final ObjectMapper objectMapper;
29-
30-
public JacksonMarshaller() {
31-
super();
32-
33-
objectMapper = new ObjectMapper();
34-
}
35-
36-
// API
37-
38-
@Override
39-
public final <T> String encode(final T entity) {
40-
Preconditions.checkNotNull(entity);
41-
String entityAsJSON = null;
42-
try {
43-
entityAsJSON = objectMapper.writeValueAsString(entity);
44-
} catch (final JsonParseException parseEx) {
45-
logger.error("", parseEx);
46-
} catch (final JsonMappingException mappingEx) {
47-
logger.error("", mappingEx);
48-
} catch (final IOException ioEx) {
49-
logger.error("", ioEx);
50-
}
51-
52-
return entityAsJSON;
53-
}
54-
55-
@Override
56-
public final <T> T decode(final String entityAsString, final Class<T> clazz) {
57-
Preconditions.checkNotNull(entityAsString);
58-
59-
T entity = null;
60-
try {
61-
entity = objectMapper.readValue(entityAsString, clazz);
62-
} catch (final JsonParseException parseEx) {
63-
logger.error("", parseEx);
64-
} catch (final JsonMappingException mappingEx) {
65-
logger.error("", mappingEx);
66-
} catch (final IOException ioEx) {
67-
logger.error("", ioEx);
68-
}
69-
70-
return entity;
71-
}
72-
73-
@SuppressWarnings("unchecked")
74-
@Override
75-
public final <T> List<T> decodeList(final String entitiesAsString, final Class<T> clazz) {
76-
Preconditions.checkNotNull(entitiesAsString);
77-
78-
List<T> entities = null;
79-
try {
80-
if (clazz.equals(Role.class)) {
81-
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Role>>() {
82-
// ...
83-
});
84-
} else if (clazz.equals(Privilege.class)) {
85-
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Privilege>>() {
86-
// ...
87-
});
88-
} else if (clazz.equals(User.class)) {
89-
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<User>>() {
90-
// ...
91-
});
92-
} else if (clazz.equals(Principal.class)) {
93-
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Principal>>() {
94-
// ...
95-
});
96-
} else {
97-
entities = objectMapper.readValue(entitiesAsString, List.class);
98-
}
99-
} catch (final JsonParseException parseEx) {
100-
logger.error("", parseEx);
101-
} catch (final JsonMappingException mappingEx) {
102-
logger.error("", mappingEx);
103-
} catch (final IOException ioEx) {
104-
logger.error("", ioEx);
105-
}
106-
107-
return entities;
108-
}
109-
110-
@Override
111-
public final String getMime() {
112-
return MediaType.APPLICATION_JSON.toString();
113-
}
114-
115-
}
1+
package org.rest.sec.client.marshall;
2+
3+
import java.io.IOException;
4+
import java.util.List;
5+
6+
import org.rest.common.client.marshall.IMarshaller;
7+
import org.rest.sec.model.Principal;
8+
import org.rest.sec.model.Privilege;
9+
import org.rest.sec.model.Role;
10+
import org.rest.sec.model.dto.User;
11+
import org.slf4j.Logger;
12+
import org.slf4j.LoggerFactory;
13+
import org.springframework.context.annotation.Profile;
14+
import org.springframework.http.MediaType;
15+
import org.springframework.stereotype.Component;
16+
17+
import com.fasterxml.jackson.core.JsonParseException;
18+
import com.fasterxml.jackson.core.type.TypeReference;
19+
import com.fasterxml.jackson.databind.JsonMappingException;
20+
import com.fasterxml.jackson.databind.ObjectMapper;
21+
import com.google.common.base.Preconditions;
22+
23+
@Component
24+
@Profile("mime_json")
25+
public final class JacksonMarshaller implements IMarshaller {
26+
private final Logger logger = LoggerFactory.getLogger(JacksonMarshaller.class);
27+
28+
private final ObjectMapper objectMapper;
29+
30+
public JacksonMarshaller() {
31+
super();
32+
33+
objectMapper = new ObjectMapper();
34+
}
35+
36+
// API
37+
38+
@Override
39+
public final <T> String encode(final T entity) {
40+
Preconditions.checkNotNull(entity);
41+
String entityAsJSON = null;
42+
try {
43+
entityAsJSON = objectMapper.writeValueAsString(entity);
44+
} catch (final JsonParseException parseEx) {
45+
logger.error("", parseEx);
46+
} catch (final JsonMappingException mappingEx) {
47+
logger.error("", mappingEx);
48+
} catch (final IOException ioEx) {
49+
logger.error("", ioEx);
50+
}
51+
52+
return entityAsJSON;
53+
}
54+
55+
@Override
56+
public final <T> T decode(final String entityAsString, final Class<T> clazz) {
57+
Preconditions.checkNotNull(entityAsString);
58+
59+
T entity = null;
60+
try {
61+
entity = objectMapper.readValue(entityAsString, clazz);
62+
} catch (final JsonParseException parseEx) {
63+
logger.error("", parseEx);
64+
} catch (final JsonMappingException mappingEx) {
65+
logger.error("", mappingEx);
66+
} catch (final IOException ioEx) {
67+
logger.error("", ioEx);
68+
}
69+
70+
return entity;
71+
}
72+
73+
@SuppressWarnings("unchecked")
74+
@Override
75+
public final <T> List<T> decodeList(final String entitiesAsString, final Class<T> clazz) {
76+
Preconditions.checkNotNull(entitiesAsString);
77+
78+
List<T> entities = null;
79+
try {
80+
if (clazz.equals(Role.class)) {
81+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Role>>() {
82+
// ...
83+
});
84+
} else if (clazz.equals(Privilege.class)) {
85+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Privilege>>() {
86+
// ...
87+
});
88+
} else if (clazz.equals(User.class)) {
89+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<User>>() {
90+
// ...
91+
});
92+
} else if (clazz.equals(Principal.class)) {
93+
entities = objectMapper.readValue(entitiesAsString, new TypeReference<List<Principal>>() {
94+
// ...
95+
});
96+
} else {
97+
entities = objectMapper.readValue(entitiesAsString, List.class);
98+
}
99+
} catch (final JsonParseException parseEx) {
100+
logger.error("", parseEx);
101+
} catch (final JsonMappingException mappingEx) {
102+
logger.error("", mappingEx);
103+
} catch (final IOException ioEx) {
104+
logger.error("", ioEx);
105+
}
106+
107+
return entities;
108+
}
109+
110+
@Override
111+
public final String getMime() {
112+
return MediaType.APPLICATION_JSON.toString();
113+
}
114+
115+
}

0 commit comments

Comments
 (0)