Skip to content

Commit

Permalink
Merge pull request #291 from aol/pcollections-module
Browse files Browse the repository at this point in the history
Jackson pcollections support
  • Loading branch information
johnmcclean authored Nov 8, 2016
2 parents fe17a83 + e1bcd9b commit 565fe80
Show file tree
Hide file tree
Showing 13 changed files with 140 additions and 61 deletions.
17 changes: 9 additions & 8 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
version=0.90
springVersion=4.3.2.RELEASE
springBootVersion=1.4.0.RELEASE
jerseyVersion=2.23.2
grizzlyVersion=2.3.26
springVersion=4.3.3.RELEASE
springBootVersion=1.4.1.RELEASE
jerseyVersion=2.24
grizzlyVersion=2.3.28
cyclopsReactVersion=1.0.2
cyclopsVersion=8.2.1
hamcrestVersion=1.3
hibernateVersion=5.1.0.Final
hibernateValidator=5.2.4.Final
springDataJPA=1.10.1.RELEASE
guavaVersion=19.0
springDataJPA=1.10.5.RELEASE
guavaVersion=20.0
javaslangDatatypeVersion=2.0.4
javaslangVersion=2.0.4
jacksonVersion=2.6.3
guavaDatatypeVersion=2.6.3
jacksonVersion=2.8.4
guavaDatatypeVersion=2.8.4
pcollectionsDatatypeVersion=2.8.4
logbackVersion=1.1.3
slf4jVersion=1.7.13
aspectJVersion=1.8.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public void runAppAndBasicTest() throws InterruptedException, ExecutionException
String json2 = rest.getJson("http://localhost:8080/event-app/status/meters");
Map<String, Integer> map2 = JacksonUtil.convertFromJson(json2, Map.class);

assertThat(json2, map2.get("com.aol.micro.server.event.metrics.MetricsCatcher.request-start-default"),
assertThat(json2, map2.get("com.aol.micro.server.event.metrics.MetricsCatcher.request-start-default-meter"),
greaterThan(0));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import com.aol.micro.server.events.SystemData;

@Component
public class Job implements ScheduledJob<Job> {
public class EventsJob implements ScheduledJob<EventsJob> {

@Override
public SystemData<String, String> scheduleAndLog() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
import org.springframework.stereotype.Component;

@Component
public class Schedular {
public class EventsSchedular {

private final Job job;
private final EventsJob job;

@Autowired
public Schedular(final Job job) {
public EventsSchedular(final EventsJob job) {
this.job = job;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void queriesStartMeterInc() {
.correlationId(10l)
.type("test")
.build()));
assertThat(registry.meter(this.config.getPrefix() + ".request-start-test")
assertThat(registry.meter(this.config.getPrefix() + ".request-start-test-meter")
.getMeanRate(),
greaterThan(0.0));
}
Expand Down
2 changes: 1 addition & 1 deletion micro-events/src/test/java/NoPackageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ public class NoPackageTest {

@Test
public void testPackageNone() {
assertThat(one.getType(NoPackageTest.class), equalTo("NoPackage"));
assertThat(one.getType(NoPackageTest.class), equalTo("NoPackageTest"));
}
}
1 change: 0 additions & 1 deletion micro-guava/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ description = 'micro-guava'
dependencies {
compile 'com.aol.cyclops:cyclops-guava:'+cyclopsVersion
compile 'com.fasterxml.jackson.datatype:jackson-datatype-guava:'+guavaDatatypeVersion

compile project(':micro-core')
compile project(':micro-jackson-configuration')
testCompile project(':micro-grizzly')
Expand Down
2 changes: 1 addition & 1 deletion micro-hibernate/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
exclude group: 'org.jboss.logging'
}
compile 'javax.transaction:jta:'+jtaVersion
compile group: 'org.hibernate', name: 'hibernate-core', version:hibernateVersion
compile (group: 'org.hibernate', name: 'hibernate-core', version:hibernateVersion)
compile group: 'org.hibernate', name: 'hibernate-entitymanager', version:hibernateVersion
compile group: 'org.springframework', name: 'spring-orm', version:"${springVersion}"

Expand Down
4 changes: 3 additions & 1 deletion micro-jackson-configuration/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
description = 'micro-jackson-configuration'
dependencies {
compile project(':micro-core')
// compile 'com.fasterxml.jackson.datatype:jackson-datatype-pcollections'+pcollectionsDatatypeVersion
compile group: 'com.fasterxml.jackson.datatype', name: 'jackson-datatype-pcollections', version: '2.8.4'
compile project(':micro-core')

}

Expand Down
2 changes: 2 additions & 0 deletions micro-jackson-configuration/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

Add Jackson Serialization to Microserver apps & add custom configurations as neccessary.

Includes serializers and deserializers for pCollections.

## Configurable Properties

properties = default
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,28 @@
import com.aol.cyclops.data.collections.extensions.persistent.PSetX;
import com.aol.micro.server.Plugin;
import com.aol.micro.server.rest.jackson.JacksonFeature;
import com.fasterxml.jackson.databind.Module;
import com.fasterxml.jackson.datatype.pcollections.PCollectionsModule;

public class JacksonPlugin implements Plugin {

@Override
public PSetX<Class<?>> jaxRsResources() {
@Override
public PSetX<Class<?>> jaxRsResources() {

return PSetX.of(JacksonFeature.class);

}
return PSetX.of(JacksonFeature.class);

@Override
public PSetX<Class> springClasses() {
}

return PSetX.of(CoreJacksonConfigurator.class,JacksonConfigurers.class);

}
@Override
public PSetX<Class> springClasses() {

return PSetX.of(CoreJacksonConfigurator.class, JacksonConfigurers.class);

}

@Override
public PSetX<Module> jacksonModules() {
return PSetX.of(new PCollectionsModule());
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.aol.micro.server.rest;


import static junit.framework.Assert.assertTrue;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertThat;

import java.util.ArrayList;
import java.util.List;
Expand All @@ -12,50 +13,62 @@
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

import lombok.Getter;
import lombok.Setter;

import org.junit.Test;
import org.pcollections.ConsPStack;
import org.pcollections.PStack;

import com.aol.cyclops.data.collections.extensions.persistent.PStackX;
import com.aol.micro.server.rest.jackson.JacksonUtil;

import lombok.Getter;
import lombok.Setter;

public class JacksonUtilTest {


@Test
public void generateSampleRequest() {

DummyQueryRequest request = new DummyQueryRequest();
request.getData().add("blah");

assertTrue(JacksonUtil.serializeToJson(request).contains("strData"));

}


@Test
public void serialiseAndDeserialise(){
DummyQueryRequest request = new DummyQueryRequest();
request.getData().add("blah");
String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request);
DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class);
assertTrue(request.getData().contains("blah"));
}



@Test
public void generateSampleRequest() {

DummyQueryRequest request = new DummyQueryRequest();
request.getData()
.add("blah");

assertTrue(JacksonUtil.serializeToJson(request)
.contains("strData"));

}

@Test
public void serialiseAndDeserialise() {
DummyQueryRequest request = new DummyQueryRequest();
request.getData()
.add("blah");
String requestStr = (String) JacksonUtil.serializeToJsonLogFailure(request);
DummyQueryRequest requestDeserialised = JacksonUtil.convertFromJson(requestStr, DummyQueryRequest.class);
assertTrue(request.getData()
.contains("blah"));
}

@Test
public void serializeToPStack() {

PStackX<Integer> list = PStackX.of(1, 2, 3, 4);
String jsonString = JacksonUtil.serializeToJson(list);

PStack<Integer> stack = JacksonUtil.convertFromJson(jsonString, ConsPStack.class);

assertThat(stack, equalTo(list.reverse()));
}

}

@XmlAccessorType(XmlAccessType.FIELD)
@XmlRootElement(name = "queryRequest")
@XmlType(name = "")
class DummyQueryRequest {

@XmlElement(name = "strData")
@Getter
@Setter
private List<String> data = new ArrayList();
@XmlElement(name = "strData")
@Getter
@Setter
private List<String> data = new ArrayList();


}

Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.aol.micro.server.testing;

import java.util.List;

import javax.ws.rs.client.Client;
import javax.ws.rs.client.ClientBuilder;
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;

import com.aol.micro.server.rest.jackson.JacksonUtil;

public class RestAgent {


public String getJson(String url) {

Client client = ClientBuilder.newClient();

WebTarget resource = client.target(url);

Builder request = resource.request();
request.accept(MediaType.APPLICATION_JSON);

return request.get(String.class);

}

public String get(String url) {

Client client = ClientBuilder.newClient();

WebTarget resource = client.target(url);

Builder request = resource.request();
request.accept(MediaType.TEXT_PLAIN);

return request.get(String.class);

}

public<T> T post(String url, Object payload,Class<T> type) {
Client client = ClientBuilder.newClient();

WebTarget resource = client.target(url);

Builder request = resource.request();
request.accept(MediaType.APPLICATION_JSON);

return request.post(Entity.entity(JacksonUtil.serializeToJson(payload),MediaType.APPLICATION_JSON), type);
}


}

0 comments on commit 565fe80

Please sign in to comment.