From 9c7debefa4fdcdb9daa6cd8e32c4123c5b2d780a Mon Sep 17 00:00:00 2001 From: Thai Nguyen Date: Tue, 19 Jul 2016 14:25:36 +0700 Subject: [PATCH 01/24] Changes configuration from XML to Java for the cxf-spring module --- apache-cxf/cxf-spring/.gitignore | 1 + apache-cxf/cxf-spring/pom.xml | 9 ++++++-- .../baeldung/cxf/spring/AppInitializer.java | 21 +++++++++++++++++ .../cxf/spring/ClientConfiguration.java | 21 +++++++++++++++++ .../cxf/spring/ServiceConfiguration.java | 23 +++++++++++++++++++ .../src/main/resources/client-beans.xml | 10 -------- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 7 ------ .../src/main/webapp/WEB-INF/web.xml | 14 ----------- .../com/baeldung/cxf/spring/StudentTest.java | 11 ++++----- 9 files changed, 77 insertions(+), 40 deletions(-) create mode 100644 apache-cxf/cxf-spring/.gitignore create mode 100644 apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/AppInitializer.java create mode 100644 apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java create mode 100644 apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java delete mode 100644 apache-cxf/cxf-spring/src/main/resources/client-beans.xml delete mode 100644 apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml diff --git a/apache-cxf/cxf-spring/.gitignore b/apache-cxf/cxf-spring/.gitignore new file mode 100644 index 0000000000..2f7896d1d1 --- /dev/null +++ b/apache-cxf/cxf-spring/.gitignore @@ -0,0 +1 @@ +target/ diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index 431c35c51d..aa72edb739 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -19,7 +19,7 @@ maven-war-plugin 2.6 - src/main/webapp/WEB-INF/web.xml + false @@ -110,8 +110,13 @@ org.springframework - spring-web + spring-webmvc ${spring.version} + + javax.servlet + javax.servlet-api + 3.1.0 + diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/AppInitializer.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/AppInitializer.java new file mode 100644 index 0000000000..036bf66a52 --- /dev/null +++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/AppInitializer.java @@ -0,0 +1,21 @@ +package com.baeldung.cxf.spring; + +import javax.servlet.ServletContext; +import javax.servlet.ServletRegistration; + +import org.apache.cxf.transport.servlet.CXFServlet; +import org.springframework.web.WebApplicationInitializer; +import org.springframework.web.context.ContextLoaderListener; +import org.springframework.web.context.support.AnnotationConfigWebApplicationContext; + +public class AppInitializer implements WebApplicationInitializer { + @Override + public void onStartup(ServletContext container) { + AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); + context.register(ServiceConfiguration.class); + container.addListener(new ContextLoaderListener(context)); + + ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new CXFServlet()); + dispatcher.addMapping("/services"); + } +} \ No newline at end of file diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java new file mode 100644 index 0000000000..a2f124705b --- /dev/null +++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java @@ -0,0 +1,21 @@ +package com.baeldung.cxf.spring; + +import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ClientConfiguration { + @Bean(name = "client") + public Object generateProxy() { + return proxyFactoryBean().create(); + } + + @Bean + public JaxWsProxyFactoryBean proxyFactoryBean() { + JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); + proxyFactory.setServiceClass(Baeldung.class); + proxyFactory.setAddress("http://localhost:8080/services/baeldung"); + return proxyFactory; + } +} \ No newline at end of file diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java new file mode 100644 index 0000000000..0d150532bf --- /dev/null +++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java @@ -0,0 +1,23 @@ +package com.baeldung.cxf.spring; + +import javax.xml.ws.Endpoint; + +import org.apache.cxf.bus.spring.SpringBus; +import org.apache.cxf.jaxws.EndpointImpl; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class ServiceConfiguration { + @Bean + public SpringBus springBus() { + return new SpringBus(); + } + + @Bean + public Endpoint endpoint() { + EndpointImpl endpoint = new EndpointImpl(springBus(), new BaeldungImpl()); + endpoint.publish("http://localhost:8080/services/baeldung"); + return endpoint; + } +} \ No newline at end of file diff --git a/apache-cxf/cxf-spring/src/main/resources/client-beans.xml b/apache-cxf/cxf-spring/src/main/resources/client-beans.xml deleted file mode 100644 index 626252b565..0000000000 --- a/apache-cxf/cxf-spring/src/main/resources/client-beans.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - diff --git a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml b/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index 9fe87ba9ee..0000000000 --- a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - diff --git a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml b/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 43a03b1d8b..0000000000 --- a/apache-cxf/cxf-spring/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - cxf - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - cxf - /services/* - - diff --git a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java index 44a9d11687..794275b4d6 100644 --- a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java +++ b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java @@ -3,15 +3,12 @@ package com.baeldung.cxf.spring; import static org.junit.Assert.assertEquals; import org.junit.Test; -import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.AnnotationConfigApplicationContext; public class StudentTest { - private ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] { "client-beans.xml" }); - private Baeldung baeldungProxy; - - { - baeldungProxy = (Baeldung) context.getBean("client"); - } + private ApplicationContext context = new AnnotationConfigApplicationContext(ClientConfiguration.class); + private Baeldung baeldungProxy = (Baeldung) context.getBean("client"); @Test public void whenUsingHelloMethod_thenCorrect() { From ec8bd5368aef5cb085e44ac1890f1898c12828a1 Mon Sep 17 00:00:00 2001 From: egimaben Date: Tue, 19 Jul 2016 21:59:52 +0300 Subject: [PATCH 02/24] fixed unit tests with wiremock --- rest-assured-tutorial/.classpath | 36 --- ...e.wst.jsdt.core.javascriptValidator.launch | 7 - rest-assured-tutorial/.gitignore | 13 - rest-assured-tutorial/.project | 36 --- rest-assured-tutorial/README.md | 7 - rest-assured-tutorial/pom.xml | 261 +++++++++++++++--- .../restassured/RestAssured2Test.java | 55 ++++ .../baeldung/restassured/RestAssuredTest.java | 137 +++------ .../restassured/RestAssuredXML2Test.java | 54 ++++ .../restassured/RestAssuredXMLTest.java | 99 +++++++ .../java/com/baeldung/restassured/Util.java | 36 +++ .../src/test/resources/.gitignore | 13 - .../src/test/resources/employees.xml | 15 - .../resources/{event0.json => event_0.json} | 14 +- .../src/test/resources/log4j.properties | 17 ++ 15 files changed, 533 insertions(+), 267 deletions(-) delete mode 100644 rest-assured-tutorial/.classpath delete mode 100644 rest-assured-tutorial/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch delete mode 100644 rest-assured-tutorial/.gitignore delete mode 100644 rest-assured-tutorial/.project create mode 100644 rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssured2Test.java create mode 100644 rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java create mode 100644 rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java create mode 100644 rest-assured-tutorial/src/test/java/com/baeldung/restassured/Util.java delete mode 100644 rest-assured-tutorial/src/test/resources/.gitignore rename rest-assured-tutorial/src/test/resources/{event0.json => event_0.json} (71%) create mode 100644 rest-assured-tutorial/src/test/resources/log4j.properties diff --git a/rest-assured-tutorial/.classpath b/rest-assured-tutorial/.classpath deleted file mode 100644 index 8ebf6d9c31..0000000000 --- a/rest-assured-tutorial/.classpath +++ /dev/null @@ -1,36 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/rest-assured-tutorial/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch b/rest-assured-tutorial/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch deleted file mode 100644 index 627021fb96..0000000000 --- a/rest-assured-tutorial/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/rest-assured-tutorial/.gitignore b/rest-assured-tutorial/.gitignore deleted file mode 100644 index 83c05e60c8..0000000000 --- a/rest-assured-tutorial/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -*.class - -#folders# -/target -/neoDb* -/data -/src/main/webapp/WEB-INF/classes -*/META-INF/* - -# Packaged files # -*.jar -*.war -*.ear \ No newline at end of file diff --git a/rest-assured-tutorial/.project b/rest-assured-tutorial/.project deleted file mode 100644 index 8333cfc36c..0000000000 --- a/rest-assured-tutorial/.project +++ /dev/null @@ -1,36 +0,0 @@ - - - rest-assured-tutorial - - - - - - org.eclipse.jdt.core.javabuilder - - - - - org.eclipse.wst.common.project.facet.core.builder - - - - - org.eclipse.wst.validation.validationbuilder - - - - - org.eclipse.m2e.core.maven2Builder - - - - - - org.eclipse.jem.workbench.JavaEMFNature - org.eclipse.wst.common.modulecore.ModuleCoreNature - org.eclipse.jdt.core.javanature - org.eclipse.m2e.core.maven2Nature - org.eclipse.wst.common.project.facet.core.nature - - diff --git a/rest-assured-tutorial/README.md b/rest-assured-tutorial/README.md index 8b81626967..e69de29bb2 100644 --- a/rest-assured-tutorial/README.md +++ b/rest-assured-tutorial/README.md @@ -1,7 +0,0 @@ -========= - -## A Guide To REST-Assured - - -### Relevant Articles: - diff --git a/rest-assured-tutorial/pom.xml b/rest-assured-tutorial/pom.xml index 12c1fe25ca..43072d3094 100644 --- a/rest-assured-tutorial/pom.xml +++ b/rest-assured-tutorial/pom.xml @@ -1,15 +1,218 @@ + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 com.baeldung - rest-assured - 0.1.0-SNAPSHOT - + rest-assured-tutorial + 1.0 rest-assured - + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 7 + 7 + + + + + + + javax.servlet + javax.servlet-api + 3.1-b06 + - + + + javax.servlet + servlet-api + 2.5 + + + + + org.eclipse.jetty + jetty-security + 9.2.0.M1 + + + + + org.eclipse.jetty + jetty-servlet + 9.2.0.M1 + + + + + org.eclipse.jetty + jetty-servlets + 9.2.0.M1 + + + + + org.eclipse.jetty + jetty-io + 9.2.0.M1 + + + + + org.eclipse.jetty + jetty-http + 9.2.0.M1 + + + + + + + org.eclipse.jetty + jetty-server + 9.2.0.M1 + + + + + org.eclipse.jetty + jetty-util + 9.2.0.M1 + + + + + + org.slf4j + slf4j-api + 1.7.21 + + + + + log4j + log4j + 1.2.17 + + + + org.slf4j + slf4j-log4j12 + 1.7.21 + + + + + + commons-logging + commons-logging + 1.2 + + + + org.apache.httpcomponents + httpcore + 4.4.5 + + + + + org.apache.commons + commons-lang3 + 3.4 + + + + + + com.github.fge + uri-template + 0.9 + + + + + com.googlecode.libphonenumber + libphonenumber + 7.4.5 + + + + javax.mail + mail + 1.4.7 + + + + joda-time + joda-time + 2.9.4 + + + + com.fasterxml.jackson.core + jackson-annotations + 2.8.0 + + + + com.fasterxml.jackson.core + jackson-databind + 2.8.0 + + + + com.fasterxml.jackson.core + jackson-core + 2.8.0 + + + + com.github.fge + msg-simple + 1.1 + + + + com.github.fge + jackson-coreutils + 1.8 + + + + + + com.google.guava + guava + 18.0 + + + com.github.fge + btf + 1.2 + + + + org.apache.httpcomponents + httpclient + 4.5.2 + + + + org.codehaus.groovy + groovy-all + 2.4.7 + + + + com.github.tomakehurst + wiremock + 2.1.7 + io.rest-assured rest-assured @@ -31,11 +234,6 @@ json-schema-core 1.2.5 - - - - - junit junit @@ -48,39 +246,12 @@ hamcrest-all 1.3 + + + commons-collections + commons-collections + 3.2.2 + - - - rest-assured - - - src/main/resources - true - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - ${maven-compiler-plugin.version} - - 1.8 - 1.8 - - - - - org.apache.maven.plugins - maven-surefire-plugin - ${maven-surefire-plugin.version} - - - - - - - - \ No newline at end of file + diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssured2Test.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssured2Test.java new file mode 100644 index 0000000000..067756823b --- /dev/null +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssured2Test.java @@ -0,0 +1,55 @@ +package com.baeldung.restassured; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.hamcrest.Matchers.hasItems; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static io.restassured.RestAssured.get; + +import com.github.tomakehurst.wiremock.WireMockServer; + +public class RestAssured2Test { + private WireMockServer wireMockServer = new WireMockServer(); + + private static final String EVENTS_PATH = "/odds"; + private static final String APPLICATION_JSON = "application/json"; + private static final String ODDS = getJson(); + + @Before + public void before() throws Exception { + System.out.println("Setting up!"); + wireMockServer.start(); + configureFor("localhost", 8080); + stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn( + aResponse().withStatus(200) + .withHeader("Content-Type", APPLICATION_JSON) + .withBody(ODDS))); + } + + @Test + public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect() { + get("/odds").then().body("odds.findAll { it.status > 0 }.price", + hasItems(5.25f, 1.2f)); + } + + private static String getJson() { + + return Util.inputStreamToString(new RestAssured2Test().getClass() + .getResourceAsStream("/odds.json")); + + } + + @After + public void after() throws Exception { + System.out.println("Running: tearDown"); + wireMockServer.stop(); + } + +} diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java index 55c7a6f0d0..a88ef2efc0 100644 --- a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java @@ -1,61 +1,68 @@ package com.baeldung.restassured; +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; import static io.restassured.RestAssured.get; -import static io.restassured.RestAssured.post; import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; import static io.restassured.module.jsv.JsonSchemaValidatorSettings.settings; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.hasItems; -import static org.hamcrest.Matchers.containsString; -import io.restassured.module.jsv.JsonSchemaValidator; -import static org.hamcrest.xml.HasXPath.hasXPath; +import org.junit.After; +import org.junit.Before; import org.junit.Test; import com.github.fge.jsonschema.SchemaVersion; import com.github.fge.jsonschema.cfg.ValidationConfiguration; import com.github.fge.jsonschema.main.JsonSchemaFactory; +import com.github.tomakehurst.wiremock.WireMockServer; public class RestAssuredTest { - @Test - public void givenJsonResponse_whenKeyValuePairMatches_thenCorrect() { - JsonSchemaFactory factory = JsonSchemaFactory - .newBuilder() - .setValidationConfiguration( - ValidationConfiguration.newBuilder() - .setDefaultVersion(SchemaVersion.DRAFTV3) - .freeze()).freeze(); - JsonSchemaValidator.settings = settings().with() - .jsonSchemaFactory(factory).and().with() - .checkedValidation(false); + private WireMockServer wireMockServer = new WireMockServer(); + private static final String EVENTS_PATH = "/events?id=390"; + private static final String APPLICATION_JSON = "application/json"; + private static final String GAME_ODDS = getEventJson(); + + @Before + public void before() throws Exception { + System.out.println("Setting up!"); + wireMockServer.start(); + configureFor("localhost", 8080); + stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn( + aResponse().withStatus(200) + .withHeader("Content-Type", APPLICATION_JSON) + .withBody(GAME_ODDS))); } @Test - public void givenJsonArrayOfSimilarObjects_whenHasGivenValuesForGivenKey_thenCorrect() { - + public void givenUrl_whenCheckingFloatValuePasses_thenCorrect() { + get("/events?id=390").then().assertThat() + .body("odd.ck", equalTo(12.2f)); } @Test public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect() { get("/events?id=390").then().statusCode(200).assertThat() - .body("data.id", equalTo(390)); + .body("id", equalTo("390")); } @Test public void givenUrl_whenJsonResponseHasArrayWithGivenValuesUnderKey_thenCorrect() { - get("/events?id=390").then().assertThat() - .body("odds.price", hasItems("1.30", "5.25")); - + .body("odds.price", hasItems(1.30f, 5.25f, 2.70f, 1.20f)); } @Test public void givenUrl_whenJsonResponseConformsToSchema_thenCorrect() { + get("/events?id=390").then().assertThat() - .body(matchesJsonSchemaInClasspath("event_0.json")); + .body(matchesJsonSchemaInClasspath("event_0.json")); } @Test @@ -64,14 +71,14 @@ public class RestAssuredTest { .newBuilder() .setValidationConfiguration( ValidationConfiguration.newBuilder() - .setDefaultVersion(SchemaVersion.DRAFTV4) - .freeze()).freeze(); + .setDefaultVersion(SchemaVersion.DRAFTV4) + .freeze()).freeze(); get("/events?id=390") - .then() - .assertThat() - .body(matchesJsonSchemaInClasspath("event_0.json").using( - jsonSchemaFactory)); + .then() + .assertThat() + .body(matchesJsonSchemaInClasspath("event_0.json").using( + jsonSchemaFactory)); } @@ -79,73 +86,21 @@ public class RestAssuredTest { public void givenUrl_whenValidatesResponseWithStaticSettings_thenCorrect() { get("/events?id=390") - .then() - .assertThat() - .body(matchesJsonSchemaInClasspath("event_0.json").using( - settings().with().checkedValidation(false))); - + .then() + .assertThat() + .body(matchesJsonSchemaInClasspath("event_0.json").using( + settings().with().checkedValidation(false))); } - @Test - public void givenUrl_whenCheckingFloatValuePasses_thenCorrect() { - get("/odd").then().assertThat().body("odd.ck", equalTo(12.2f)); + @After + public void after() throws Exception { + System.out.println("Running: tearDown"); + wireMockServer.stop(); } - @Test - public void givenUrl_whenXmlResponseValueTestsEqual_thenCorrect() { - post("/employees").then().assertThat() - .body("employees.employee.first-name", equalTo("Jane")); - } - - @Test - public void givenUrl_whenMultipleXmlValuesTestEqual_thenCorrect() { - post("/employees").then().assertThat() - .body("employees.employee.first-name", equalTo("Jane")) - .body("employees.employee.last-name", equalTo("Daisy")) - .body("employees.employee.sex", equalTo("f")); - } - - @Test - public void givenUrl_whenMultipleXmlValuesTestEqualInShortHand_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body("employees.employee.first-name", equalTo("Jane"), - "employees.employee.last-name", equalTo("Daisy"), - "employees.employee.sex", equalTo("f")); - } - - @Test - public void givenUrl_whenValidatesXmlUsingXpath_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body(hasXPath("/employees/employee/first-name", - containsString("Ja"))); - - } - - @Test - public void givenUrl_whenValidatesXmlUsingXpath2_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body(hasXPath("/employees/employee/first-name[text()='Jane']")); - - } - - @Test - public void givenUrl_whenVerifiesScienceTeacherFromXml_thenCorrect() { - get("/teachers") - .then() - .body("teachers.teacher.find { it.@department == 'science' }.subject", - hasItems("math", "physics")); - } - - @Test - public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect() { - get("/odds").then().body("odds.findAll { it.status > 0 }.price", - hasItems(1.30f, 1.20f)); + private static String getEventJson() { + return Util.inputStreamToString(new RestAssuredTest().getClass() + .getResourceAsStream("/event_0.json")); } } diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java new file mode 100644 index 0000000000..597280c7c0 --- /dev/null +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java @@ -0,0 +1,54 @@ +package com.baeldung.restassured; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static org.hamcrest.Matchers.hasItems; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import static io.restassured.RestAssured.get; + +import com.github.tomakehurst.wiremock.WireMockServer; + +public class RestAssuredXML2Test { + private WireMockServer wireMockServer = new WireMockServer(); + + private static final String EVENTS_PATH = "/teachers"; + private static final String APPLICATION_XML = "application/xml"; + private static final String TEACHERS = getXml(); + + @Before + public void before() throws Exception { + System.out.println("Setting up!"); + wireMockServer.start(); + configureFor("localhost", 8080); + stubFor(get(urlEqualTo(EVENTS_PATH)).willReturn( + aResponse().withStatus(200) + .withHeader("Content-Type", APPLICATION_XML) + .withBody(TEACHERS))); + } + @Test + public void givenUrl_whenVerifiesScienceTeacherFromXml_thenCorrect() { + get("/teachers") + .then() + .body("teachers.teacher.find { it.@department == 'science' }.subject", + hasItems("math", "physics")); + } + private static String getXml() { + + return Util + .inputStreamToString(new RestAssuredXML2Test().getClass().getResourceAsStream("/teachers.xml")); + +} + @After +public void after() throws Exception { + System.out.println("Running: tearDown"); + wireMockServer.stop(); +} + +} diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java new file mode 100644 index 0000000000..315dc76169 --- /dev/null +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java @@ -0,0 +1,99 @@ +package com.baeldung.restassured; + +import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; +import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; +import static com.github.tomakehurst.wiremock.client.WireMock.get; +import static com.github.tomakehurst.wiremock.client.WireMock.post; +import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; +import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; +import static io.restassured.RestAssured.post; +import static io.restassured.RestAssured.get; +import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; +import static io.restassured.module.jsv.JsonSchemaValidatorSettings.settings; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.xml.HasXPath.hasXPath; + +import java.io.FileNotFoundException; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.github.fge.jsonschema.SchemaVersion; +import com.github.fge.jsonschema.cfg.ValidationConfiguration; +import com.github.fge.jsonschema.main.JsonSchemaFactory; +import com.github.tomakehurst.wiremock.WireMockServer; +public class RestAssuredXMLTest { + private WireMockServer wireMockServer = new WireMockServer(); + private static final String EVENTS_PATH = "/employees"; + private static final String APPLICATION_XML = "application/xml"; + private static final String EMPLOYEES = getXml(); + + @Before + public void before() throws Exception { + System.out.println("Setting up!"); + wireMockServer.start(); + configureFor("localhost", 8080); + stubFor(post(urlEqualTo(EVENTS_PATH)).willReturn( + aResponse().withStatus(200) + .withHeader("Content-Type", APPLICATION_XML) + .withBody(EMPLOYEES))); + } + @Test + public void givenUrl_whenXmlResponseValueTestsEqual_thenCorrect() { + post("/employees").then().assertThat() + .body("employees.employee.first-name", equalTo("Jane")); + } + + @Test + public void givenUrl_whenMultipleXmlValuesTestEqual_thenCorrect() { + post("/employees").then().assertThat() + .body("employees.employee.first-name", equalTo("Jane")) + .body("employees.employee.last-name", equalTo("Daisy")) + .body("employees.employee.sex", equalTo("f")); + } + + @Test + public void givenUrl_whenMultipleXmlValuesTestEqualInShortHand_thenCorrect() { + post("/employees") + .then() + .assertThat() + .body("employees.employee.first-name", equalTo("Jane"), + "employees.employee.last-name", equalTo("Daisy"), + "employees.employee.sex", equalTo("f")); + } + + @Test + public void givenUrl_whenValidatesXmlUsingXpath_thenCorrect() { + post("/employees") + .then() + .assertThat() + .body(hasXPath("/employees/employee/first-name", + containsString("Ja"))); + + } + + @Test + public void givenUrl_whenValidatesXmlUsingXpath2_thenCorrect() { + post("/employees") + .then() + .assertThat() + .body(hasXPath("/employees/employee/first-name[text()='Jane']")); + + } + + + private static String getXml() { + + return Util + .inputStreamToString(new RestAssuredXMLTest().getClass().getResourceAsStream("/employees.xml")); + +} + @After +public void after() throws Exception { + System.out.println("Running: tearDown"); + wireMockServer.stop(); +} +} diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/Util.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/Util.java new file mode 100644 index 0000000000..c75c52eb34 --- /dev/null +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/Util.java @@ -0,0 +1,36 @@ +package com.baeldung.restassured; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; + +public class Util { + public static String inputStreamToString(InputStream is) { + BufferedReader br = null; + StringBuilder sb = new StringBuilder(); + + String line; + try { + + br = new BufferedReader(new InputStreamReader(is)); + while ((line = br.readLine()) != null) { + sb.append(line); + } + + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (br != null) { + try { + br.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + + return sb.toString(); + + } +} diff --git a/rest-assured-tutorial/src/test/resources/.gitignore b/rest-assured-tutorial/src/test/resources/.gitignore deleted file mode 100644 index 83c05e60c8..0000000000 --- a/rest-assured-tutorial/src/test/resources/.gitignore +++ /dev/null @@ -1,13 +0,0 @@ -*.class - -#folders# -/target -/neoDb* -/data -/src/main/webapp/WEB-INF/classes -*/META-INF/* - -# Packaged files # -*.jar -*.war -*.ear \ No newline at end of file diff --git a/rest-assured-tutorial/src/test/resources/employees.xml b/rest-assured-tutorial/src/test/resources/employees.xml index 64e382976d..388b422210 100644 --- a/rest-assured-tutorial/src/test/resources/employees.xml +++ b/rest-assured-tutorial/src/test/resources/employees.xml @@ -4,19 +4,4 @@ Daisy f - - John - Doe - m - - - Billy - Getty - m - - - Hill - Clinton - f - \ No newline at end of file diff --git a/rest-assured-tutorial/src/test/resources/event0.json b/rest-assured-tutorial/src/test/resources/event_0.json similarity index 71% rename from rest-assured-tutorial/src/test/resources/event0.json rename to rest-assured-tutorial/src/test/resources/event_0.json index 77e26c347e..a6e45239ec 100644 --- a/rest-assured-tutorial/src/test/resources/event0.json +++ b/rest-assured-tutorial/src/test/resources/event_0.json @@ -1,5 +1,11 @@ { "id": "390", + "odd": { + "price": "1.20", + "status": 2, + "ck": 12.2, + "name": "2" + }, "data": { "countryId": 35, "countryName": "Norway", @@ -9,25 +15,25 @@ "time": "2016-06-12T12:00:00Z" }, "odds": [{ - "price": 1.30, + "price": "1.30", "status": 0, "ck": 12.2, "name": "1" }, { - "price": 5.25, + "price":"5.25", "status": 1, "ck": 13.1, "name": "X" }, { - "price": 2.70, + "price": "2.70", "status": 0, "ck": 12.2, "name": "0" }, { - "price": 1.20, + "price": "1.20", "status": 2, "ck": 13.1, "name": "2" diff --git a/rest-assured-tutorial/src/test/resources/log4j.properties b/rest-assured-tutorial/src/test/resources/log4j.properties new file mode 100644 index 0000000000..e4b76524e8 --- /dev/null +++ b/rest-assured-tutorial/src/test/resources/log4j.properties @@ -0,0 +1,17 @@ +## Logger configure file for myproject +log.dir=C:/ProgramData/radixbase/ +datestamp=yyyy-MM-dd HH:mm:ss +log4j.rootLogger=TRACE, file, console + +log4j.appender.file=org.apache.log4j.RollingFileAppender +log4j.appender.file.maxFileSize=1GB +log4j.appender.file.maxBackupIndex=5 +log4j.appender.file.File=log/mydebug.log +log4j.appender.file.threshold=TRACE +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{${datestamp}} %5p: [%c] - %m%n + +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.Threshold=INFO +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{${datestamp}} %5p\: [%c] - %m%n \ No newline at end of file From e580d248df1abe120a6ae0c6e9af5a886fa96efb Mon Sep 17 00:00:00 2001 From: egimaben Date: Wed, 20 Jul 2016 10:45:38 +0300 Subject: [PATCH 03/24] fixed merge conflicts --- rest-assured-tutorial/pom.xml | 88 +--------- .../baeldung/restassured/RestAssuredTest.java | 160 +----------------- 2 files changed, 9 insertions(+), 239 deletions(-) diff --git a/rest-assured-tutorial/pom.xml b/rest-assured-tutorial/pom.xml index 90875a19ac..43072d3094 100644 --- a/rest-assured-tutorial/pom.xml +++ b/rest-assured-tutorial/pom.xml @@ -5,7 +5,6 @@ rest-assured-tutorial 1.0 rest-assured -<<<<<<< HEAD @@ -214,108 +213,38 @@ wiremock 2.1.7 -======= - - - - 3.5.1 - 2.19.1 - - 1.10.19 - 4.12 - 2.1.7 - 1.3 - 1.2.5 - 2.2.6 - 3.0.0 - - - 1.7.13 - 1.1.3 - - - - - - - org.slf4j - slf4j-api - ${org.slf4j.version} - - - ch.qos.logback - logback-classic - ${logback.version} - - - - org.slf4j - jcl-over-slf4j - ${org.slf4j.version} - runtime - - - org.slf4j - log4j-over-slf4j - ${org.slf4j.version} - - ->>>>>>> upstream/master io.rest-assured rest-assured - ${rest-assured.version} + 3.0.0 test - io.rest-assured json-schema-validator - ${rest-assured.version} + 3.0.0 - com.github.fge json-schema-validator - ${json-schema-validator.version} + 2.2.6 - com.github.fge json-schema-core - ${json-schema-core.version} + 1.2.5 -<<<<<<< HEAD junit junit 4.3 test -======= - - - - - junit - junit - ${junit.version} - test - - - - com.github.tomakehurst - wiremock - ${wiremock.version} - test - ->>>>>>> upstream/master org.hamcrest hamcrest-all - ${hamcrest-all.version} - test + 1.3 @@ -324,12 +253,5 @@ 3.2.2 - - org.mockito - mockito-core - ${mockito.version} - test - - diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java index 0fe7df7138..a88ef2efc0 100644 --- a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java @@ -1,29 +1,14 @@ package com.baeldung.restassured; -<<<<<<< HEAD import static com.github.tomakehurst.wiremock.client.WireMock.aResponse; import static com.github.tomakehurst.wiremock.client.WireMock.configureFor; import static com.github.tomakehurst.wiremock.client.WireMock.get; import static com.github.tomakehurst.wiremock.client.WireMock.stubFor; import static com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo; -======= -import com.github.fge.jsonschema.SchemaVersion; -import com.github.fge.jsonschema.cfg.ValidationConfiguration; -import com.github.fge.jsonschema.main.JsonSchemaFactory; -import com.github.tomakehurst.wiremock.WireMockServer; -import com.github.tomakehurst.wiremock.client.WireMock; -import io.restassured.module.jsv.JsonSchemaValidator; -import org.junit.Ignore; -import org.junit.Test; - -import static com.github.tomakehurst.wiremock.client.WireMock.*; ->>>>>>> upstream/master import static io.restassured.RestAssured.get; import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath; import static io.restassured.module.jsv.JsonSchemaValidatorSettings.settings; -import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.equalTo; -<<<<<<< HEAD import static org.hamcrest.Matchers.hasItems; import org.junit.After; @@ -34,10 +19,6 @@ import com.github.fge.jsonschema.SchemaVersion; import com.github.fge.jsonschema.cfg.ValidationConfiguration; import com.github.fge.jsonschema.main.JsonSchemaFactory; import com.github.tomakehurst.wiremock.WireMockServer; -======= -import static org.hamcrest.xml.HasXPath.hasXPath; - ->>>>>>> upstream/master public class RestAssuredTest { @@ -63,91 +44,28 @@ public class RestAssuredTest { .body("odd.ck", equalTo(12.2f)); } - private WireMockServer wireMockServer = new WireMockServer(); - private static final String EVENTS_PATH = "/events?id=390"; - private static final String APPLICATION_JSON = "application/json"; - - private static final String GAME_ODDS = "" + - "{" + - " \"id\": 390," + - " \"data\": {" + - " \"countryId\": 35," + - " \"countryName\": \"Norway\"," + - " \"leagueName\": \"Norway 3\"," + - " \"status\": 0," + - " \"sportName\": \"Soccer\"," + - " \"time\": \"2016-06-12T12:00:00Z\"" + - " }," + - " \"odds\": [" + - " {" + - " \"price\": \"1.30\"," + - " \"status\": 0," + - " \"ck\": \"1\"," + - " \"name\": \"1\"" + - " }," + - " {" + - " \"price\": \"5.25\"," + - " \"status\": 0," + - " \"ck\": \"X\"," + - " \"name\": \"X\"" + - " }" + - " ]" + - "}"; - - @Test - public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect() { - - wireMockServer.start(); - configureFor("localhost", 8080); - - stubFor(WireMock.get(urlEqualTo(EVENTS_PATH)).willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", APPLICATION_JSON) - .withBody(GAME_ODDS))); + public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect() { get("/events?id=390").then().statusCode(200).assertThat() -<<<<<<< HEAD .body("id", equalTo("390")); -======= - .body("id", equalTo(390)); ->>>>>>> upstream/master - wireMockServer.stop(); } - @Test public void givenUrl_whenJsonResponseHasArrayWithGivenValuesUnderKey_thenCorrect() { -<<<<<<< HEAD get("/events?id=390").then().assertThat() .body("odds.price", hasItems(1.30f, 5.25f, 2.70f, 1.20f)); -======= - - wireMockServer.start(); - configureFor("localhost", 8080); - - stubFor(WireMock.get(urlEqualTo(EVENTS_PATH)).willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", APPLICATION_JSON) - .withBody(GAME_ODDS))); - - get("/events?id=390").then().assertThat() - .body("odds.price", hasItems("1.30", "5.25")); - - wireMockServer.stop(); ->>>>>>> upstream/master } - - @Test @Ignore + @Test public void givenUrl_whenJsonResponseConformsToSchema_thenCorrect() { get("/events?id=390").then().assertThat() .body(matchesJsonSchemaInClasspath("event_0.json")); } - @Test @Ignore + @Test public void givenUrl_whenValidatesResponseWithInstanceSettings_thenCorrect() { JsonSchemaFactory jsonSchemaFactory = JsonSchemaFactory .newBuilder() @@ -164,11 +82,10 @@ public class RestAssuredTest { } - @Test @Ignore + @Test public void givenUrl_whenValidatesResponseWithStaticSettings_thenCorrect() { get("/events?id=390") -<<<<<<< HEAD .then() .assertThat() .body(matchesJsonSchemaInClasspath("event_0.json").using( @@ -184,75 +101,6 @@ public class RestAssuredTest { private static String getEventJson() { return Util.inputStreamToString(new RestAssuredTest().getClass() .getResourceAsStream("/event_0.json")); -======= - .then() - .assertThat() - .body(matchesJsonSchemaInClasspath("event_0.json").using( - settings().with().checkedValidation(false))); - - } - - @Test @Ignore - public void givenUrl_whenCheckingFloatValuePasses_thenCorrect() { - get("/odd").then().assertThat().body("odd.ck", equalTo(12.2f)); - } - - @Test @Ignore - public void givenUrl_whenXmlResponseValueTestsEqual_thenCorrect() { - post("/employees").then().assertThat() - .body("employees.employee.first-name", equalTo("Jane")); - } - - @Test @Ignore - public void givenUrl_whenMultipleXmlValuesTestEqual_thenCorrect() { - post("/employees").then().assertThat() - .body("employees.employee.first-name", equalTo("Jane")) - .body("employees.employee.last-name", equalTo("Daisy")) - .body("employees.employee.sex", equalTo("f")); - } - - @Test @Ignore - public void givenUrl_whenMultipleXmlValuesTestEqualInShortHand_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body("employees.employee.first-name", equalTo("Jane"), - "employees.employee.last-name", equalTo("Daisy"), - "employees.employee.sex", equalTo("f")); - } - - @Test @Ignore - public void givenUrl_whenValidatesXmlUsingXpath_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body(hasXPath("/employees/employee/first-name", - containsString("Ja"))); - - } - - @Test @Ignore - public void givenUrl_whenValidatesXmlUsingXpath2_thenCorrect() { - post("/employees") - .then() - .assertThat() - .body(hasXPath("/employees/employee/first-name[text()='Jane']")); - - } - - @Test @Ignore - public void givenUrl_whenVerifiesScienceTeacherFromXml_thenCorrect() { - get("/teachers") - .then() - .body("teachers.teacher.find { it.@department == 'science' }.subject", - hasItems("math", "physics")); - } - - @Test @Ignore - public void givenUrl_whenVerifiesOddPricesAccuratelyByStatus_thenCorrect() { - get("/odds").then().body("odds.findAll { it.status > 0 }.price", - hasItems(1.30f, 1.20f)); ->>>>>>> upstream/master } } From b9c412689d0e858256cd22c540ad5615ae1d6754 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Gonz=C3=A1lez?= Date: Wed, 20 Jul 2016 14:31:51 +0200 Subject: [PATCH 04/24] Fix on the test and compression to match article (#520) * Add new module for mocks comparison. * Add sources for testing. * Changes on testCase. * Enter some tests for mockito. * More tests for Mockito. * Even more tests. * Add the rest of the mocking libraries. * Javadoc on test. * Test bare bones for EasyMock. * Fist kind of test and setup. * Add tests using EasyMock with a change on LoginService. * Create LoginControllerTest.java * Test setup * [JMockit] No method called test. * [JMockit] Two methods called test. * [JMockit] One method called test. * [JMockit] Exception mock test * [JMockit] Mocked object to pass around test. * [JMockit] Custom matcher test. * [JMockit] Partial mocking test. * [JMockit] Fix with IDE. * Not stubs. Mocks. MOCKS!!! * Remove unnecesary import. * Use correct encoding. Was having problems with buildings. * Remove failing module. * Create new module mocks and move mock-comparisons there. * Add jmockit module. * Add model class. * Add collaborator class. * Add performer class. * Add performer test. * Fix * Add interface for tests. * Test for any. * Test for with. * Test for null. * Test for times. * Test for arg that. * Test for result and returns. * Test for delegate. * Add verifications to any tests. * Add verifications to with test. * Add verification examples to methods using null. * Add verifications to methods using times. * Formatting. * Compress tests and fix one test. --- .../mocks/jmockit/ExpectationsTest.java | 28 +++++-------------- 1 file changed, 7 insertions(+), 21 deletions(-) diff --git a/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java index d1f3fa9e85..239bd814cd 100644 --- a/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java +++ b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java @@ -82,10 +82,8 @@ public class ExpectationsTest { public void testWithTimes(@Mocked ExpectationsCollaborator mock) { new Expectations() { { - // exactly 2 invocations are expected - mock.methodForTimes1(); - times = 2; - mock.methodForTimes2(); // "minTimes = 1" is implied + mock.methodForTimes1(); times = 2; + mock.methodForTimes2(); } }; @@ -98,10 +96,7 @@ public class ExpectationsTest { new Verifications() { { - // we expect from 1 to 3 invocations - mock.methodForTimes3(); - minTimes = 1; - maxTimes = 3; + mock.methodForTimes3(); minTimes = 1; maxTimes = 3; } }; } @@ -117,9 +112,7 @@ public class ExpectationsTest { } @Override - public void describeTo(Description description) { - // NOOP - } + public void describeTo(Description description) { } })); } }; @@ -130,18 +123,14 @@ public class ExpectationsTest { public void testResultAndReturns(@Mocked ExpectationsCollaborator mock) { new StrictExpectations() { { - // return "foo", an exception and lastly "bar" mock.methodReturnsString(); result = "foo"; result = new Exception(); result = "bar"; - // return 1, 2, 3 mock.methodReturnsInt(); result = new int[] { 1, 2, 3 }; - // return "foo" and "bar" mock.methodReturnsString(); returns("foo", "bar"); - // return only 1 mock.methodReturnsInt(); result = 1; } @@ -164,11 +153,9 @@ public class ExpectationsTest { @Test public void testDelegate(@Mocked ExpectationsCollaborator mock) { - new StrictExpectations() { + new Expectations() { { - // return "foo", an exception and lastly "bar" mock.methodForDelegate(anyInt); - times = 2; result = new Delegate() { public int delegate(int i) throws Exception { if (i < 3) { @@ -180,11 +167,10 @@ public class ExpectationsTest { }; } }; + assertEquals("Should return 5", 5, mock.methodForDelegate(1)); try { mock.methodForDelegate(3); - } catch (Exception e) { - // NOOP - } + } catch (Exception e) { } } } From 34414b2a43054aeabfc2e57acd35dd214fbc124f Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Wed, 20 Jul 2016 19:17:08 +0300 Subject: [PATCH 05/24] Refactor JMockit examples --- .../baeldung/mocks/jmockit/Collaborator.java | 2 + .../org/baeldung/mocks/jmockit/Model.java | 4 +- .../mocks/jmockit/ExpectationsTest.java | 186 ++++++++---------- .../baeldung/mocks/jmockit/PerformerTest.java | 2 + 4 files changed, 90 insertions(+), 104 deletions(-) diff --git a/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Collaborator.java b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Collaborator.java index ef271b9aff..60da12fa7c 100644 --- a/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Collaborator.java +++ b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Collaborator.java @@ -1,9 +1,11 @@ package org.baeldung.mocks.jmockit; public class Collaborator { + public boolean collaborate(String string){ return false; } + public void receive(boolean bool){ //NOOP } diff --git a/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Model.java b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Model.java index c3b63d11b4..79ae24c2f5 100644 --- a/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Model.java +++ b/mocks/jmockit/src/main/java/org/baeldung/mocks/jmockit/Model.java @@ -1,7 +1,7 @@ package org.baeldung.mocks.jmockit; public class Model { - public String getInfo(){ - return "info"; + public String getInfo() { + return "info"; } } diff --git a/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java index 239bd814cd..1c72647133 100644 --- a/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java +++ b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/ExpectationsTest.java @@ -1,21 +1,20 @@ package org.baeldung.mocks.jmockit; -import static org.junit.Assert.*; - -import java.util.ArrayList; -import java.util.List; - -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.junit.Test; -import org.junit.runner.RunWith; - import mockit.Delegate; import mockit.Expectations; import mockit.Mocked; import mockit.StrictExpectations; import mockit.Verifications; import mockit.integration.junit4.JMockit; +import org.hamcrest.BaseMatcher; +import org.hamcrest.Description; +import org.junit.Test; +import org.junit.runner.RunWith; + +import java.util.ArrayList; +import java.util.List; + +import static org.junit.Assert.assertEquals; @RunWith(JMockit.class) @SuppressWarnings("unchecked") @@ -23,119 +22,103 @@ public class ExpectationsTest { @Test public void testForAny(@Mocked ExpectationsCollaborator mock) throws Exception { - new Expectations() { - { - mock.methodForAny1(anyString, anyInt, anyBoolean); - result = "any"; - } - }; + new Expectations() {{ + mock.methodForAny1(anyString, anyInt, anyBoolean); + result = "any"; + }}; assertEquals("any", mock.methodForAny1("barfooxyz", 0, Boolean.FALSE)); mock.methodForAny2(2L, new ArrayList<>()); - new Verifications() { - { - mock.methodForAny2(anyLong, (List) any); - } - }; + new Verifications() {{ + mock.methodForAny2(anyLong, (List) any); + }}; } @Test public void testForWith(@Mocked ExpectationsCollaborator mock) throws Exception { - new Expectations() { - { - mock.methodForWith1(withSubstring("foo"), withNotEqual(1)); - result = "with"; - } - }; - + new Expectations() {{ + mock.methodForWith1(withSubstring("foo"), withNotEqual(1)); + result = "with"; + }}; + assertEquals("with", mock.methodForWith1("barfooxyz", 2)); mock.methodForWith2(Boolean.TRUE, new ArrayList<>()); - - new Verifications() { - { - mock.methodForWith2(withNotNull(), withInstanceOf(List.class)); - } - }; + + new Verifications() {{ + mock.methodForWith2(withNotNull(), withInstanceOf(List.class)); + }}; } @Test public void testWithNulls(@Mocked ExpectationsCollaborator mock) { - new Expectations() { - { - mock.methodForNulls1(anyString, null); - result = "null"; - } - }; - + new Expectations() {{ + mock.methodForNulls1(anyString, null); + result = "null"; + }}; + assertEquals("null", mock.methodForNulls1("blablabla", new ArrayList())); mock.methodForNulls2("blablabla", null); - - new Verifications() { - { - mock.methodForNulls2(anyString, (List) withNull()); - } - }; + + new Verifications() {{ + mock.methodForNulls2(anyString, (List) withNull()); + }}; } @Test public void testWithTimes(@Mocked ExpectationsCollaborator mock) { - new Expectations() { - { - mock.methodForTimes1(); times = 2; - mock.methodForTimes2(); - } - }; - + new Expectations() {{ + mock.methodForTimes1(); + times = 2; + mock.methodForTimes2(); + }}; + mock.methodForTimes1(); mock.methodForTimes1(); mock.methodForTimes2(); mock.methodForTimes3(); mock.methodForTimes3(); mock.methodForTimes3(); - - new Verifications() { - { - mock.methodForTimes3(); minTimes = 1; maxTimes = 3; - } - }; + + new Verifications() {{ + mock.methodForTimes3(); + minTimes = 1; + maxTimes = 3; + }}; } @Test public void testCustomArgumentMatching(@Mocked ExpectationsCollaborator mock) { - new Expectations() { - { - mock.methodForArgThat(withArgThat(new BaseMatcher() { - @Override - public boolean matches(Object item) { - return item instanceof Model && "info".equals(((Model) item).getInfo()); - } + new Expectations() {{ + mock.methodForArgThat(withArgThat(new BaseMatcher() { + @Override + public boolean matches(Object item) { + return item instanceof Model && "info".equals(((Model) item).getInfo()); + } - @Override - public void describeTo(Description description) { } - })); - } - }; + @Override + public void describeTo(Description description) { + } + })); + }}; mock.methodForArgThat(new Model()); } @Test public void testResultAndReturns(@Mocked ExpectationsCollaborator mock) { - new StrictExpectations() { - { - mock.methodReturnsString(); - result = "foo"; - result = new Exception(); - result = "bar"; - mock.methodReturnsInt(); - result = new int[] { 1, 2, 3 }; - mock.methodReturnsString(); - returns("foo", "bar"); - mock.methodReturnsInt(); - result = 1; - } - }; - + new StrictExpectations() {{ + mock.methodReturnsString(); + result = "foo"; + result = new Exception(); + result = "bar"; + mock.methodReturnsInt(); + result = new int[]{1, 2, 3}; + mock.methodReturnsString(); + returns("foo", "bar"); + mock.methodReturnsInt(); + result = 1; + }}; + assertEquals("Should return foo", "foo", mock.methodReturnsString()); try { mock.methodReturnsString(); @@ -153,24 +136,23 @@ public class ExpectationsTest { @Test public void testDelegate(@Mocked ExpectationsCollaborator mock) { - new Expectations() { - { - mock.methodForDelegate(anyInt); - result = new Delegate() { - public int delegate(int i) throws Exception { - if (i < 3) { - return 5; - } else { - throw new Exception(); - } + new Expectations() {{ + mock.methodForDelegate(anyInt); + result = new Delegate() { + public int delegate(int i) throws Exception { + if (i < 3) { + return 5; + } else { + throw new Exception(); } - }; - } - }; - + } + }; + }}; + assertEquals("Should return 5", 5, mock.methodForDelegate(1)); try { mock.methodForDelegate(3); - } catch (Exception e) { } + } catch (Exception e) { + } } } diff --git a/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/PerformerTest.java b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/PerformerTest.java index c99ae844c3..2b1b3be0f7 100644 --- a/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/PerformerTest.java +++ b/mocks/jmockit/src/test/java/org/baeldung/mocks/jmockit/PerformerTest.java @@ -21,7 +21,9 @@ public class PerformerTest { model.getInfo();result = "bar"; collaborator.collaborate("bar"); result = true; }}; + performer.perform(model); + new Verifications() {{ collaborator.receive(true); }}; From 042878628f970029a3ac698ced3336480a21344c Mon Sep 17 00:00:00 2001 From: maibin Date: Wed, 20 Jul 2016 09:17:38 -0700 Subject: [PATCH 06/24] Expression-Based Access Control (#517) * Expression-Based Access Control PermitAll, hasRole, hasAnyRole etc. I modified classes regards to Security * Added test cases for Spring Security Expressions --- .../spring/SecurityWithoutCsrfConfig.java | 5 +- .../java/org/baeldung/spring/WebConfig.java | 35 ++-- .../web/controller/BankController.java | 27 ++-- .../web/controller/FooController.java | 136 ++++++++-------- .../web/controller/HomeController.java | 14 ++ .../web/controller/RootController.java | 95 +++++------ .../web/controller/UserController.java | 151 +++++++++--------- .../csrf/CsrfAbstractIntegrationTest.java | 36 +++-- .../csrf/CsrfDisabledIntegrationTest.java | 36 ++++- 9 files changed, 289 insertions(+), 246 deletions(-) create mode 100644 spring-security-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/SecurityWithoutCsrfConfig.java b/spring-security-rest-full/src/main/java/org/baeldung/spring/SecurityWithoutCsrfConfig.java index fcb28f6ae2..aeb2428326 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/spring/SecurityWithoutCsrfConfig.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/spring/SecurityWithoutCsrfConfig.java @@ -44,8 +44,9 @@ public class SecurityWithoutCsrfConfig extends WebSecurityConfigurerAdapter { http .csrf().disable() .authorizeRequests() - .antMatchers("/admin/*").hasAnyRole("ROLE_ADMIN") - .anyRequest().authenticated() + .antMatchers("/auth/admin/*").hasRole("ADMIN") + .antMatchers("/auth/*").hasAnyRole("ADMIN","USER") + .antMatchers("/*").permitAll() .and() .httpBasic() .and() diff --git a/spring-security-rest-full/src/main/java/org/baeldung/spring/WebConfig.java b/spring-security-rest-full/src/main/java/org/baeldung/spring/WebConfig.java index 143e52d94e..3e5d6435b3 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/spring/WebConfig.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/spring/WebConfig.java @@ -14,24 +14,25 @@ import org.springframework.web.servlet.view.InternalResourceViewResolver; @EnableWebMvc public class WebConfig extends WebMvcConfigurerAdapter { - public WebConfig() { - super(); - } + public WebConfig() { + super(); + } - @Bean - public ViewResolver viewResolver() { - final InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); - viewResolver.setPrefix("/WEB-INF/view/"); - viewResolver.setSuffix(".jsp"); - return viewResolver; - } + @Bean + public ViewResolver viewResolver() { + final InternalResourceViewResolver viewResolver = new InternalResourceViewResolver(); + viewResolver.setPrefix("/WEB-INF/view/"); + viewResolver.setSuffix(".jsp"); + return viewResolver; + } - // API - @Override - public void addViewControllers(final ViewControllerRegistry registry) { - super.addViewControllers(registry); - registry.addViewController("/graph.html"); - registry.addViewController("/csrfHome.html"); - } + // API + @Override + public void addViewControllers(final ViewControllerRegistry registry) { + super.addViewControllers(registry); + registry.addViewController("/graph.html"); + registry.addViewController("/csrfHome.html"); + registry.addViewController("/homepage.html"); + } } \ No newline at end of file diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/BankController.java b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/BankController.java index 1a4322c611..64a29f20d3 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/BankController.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/BankController.java @@ -12,21 +12,22 @@ import org.springframework.web.bind.annotation.ResponseStatus; // to test csrf @Controller +@RequestMapping(value = "/auth/") public class BankController { - private final Logger logger = LoggerFactory.getLogger(getClass()); + private final Logger logger = LoggerFactory.getLogger(getClass()); - @RequestMapping(value = "/transfer", method = RequestMethod.GET) - @ResponseBody - public int transfer(@RequestParam("accountNo") final int accountNo, @RequestParam("amount") final int amount) { - logger.info("Transfer to {}", accountNo); - return amount; - } + @RequestMapping(value = "/transfer", method = RequestMethod.GET) + @ResponseBody + public int transfer(@RequestParam("accountNo") final int accountNo, @RequestParam("amount") final int amount) { + logger.info("Transfer to {}", accountNo); + return amount; + } - // write - just for test - @RequestMapping(value = "/transfer", method = RequestMethod.POST) - @ResponseStatus(HttpStatus.OK) - public void create(@RequestParam("accountNo") final int accountNo, @RequestParam("amount") final int amount) { - logger.info("Transfer to {}", accountNo); + // write - just for test + @RequestMapping(value = "/transfer", method = RequestMethod.POST) + @ResponseStatus(HttpStatus.OK) + public void create(@RequestParam("accountNo") final int accountNo, @RequestParam("amount") final int amount) { + logger.info("Transfer to {}", accountNo); - } + } } diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/FooController.java b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/FooController.java index 20307447b2..1e00d6350b 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/FooController.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/FooController.java @@ -29,93 +29,93 @@ import org.springframework.web.util.UriComponentsBuilder; import com.google.common.base.Preconditions; @Controller -@RequestMapping(value = "/foos") +@RequestMapping(value = "/auth/foos") public class FooController { - @Autowired - private ApplicationEventPublisher eventPublisher; + @Autowired + private ApplicationEventPublisher eventPublisher; - @Autowired - private IFooService service; + @Autowired + private IFooService service; - public FooController() { - super(); - } + public FooController() { + super(); + } - // API + // API - @RequestMapping(method = RequestMethod.GET, value = "/count") - @ResponseBody - @ResponseStatus(value = HttpStatus.OK) - public long count() { - return 2l; - } + @RequestMapping(method = RequestMethod.GET, value = "/count") + @ResponseBody + @ResponseStatus(value = HttpStatus.OK) + public long count() { + return 2l; + } - // read - one + // read - one - @RequestMapping(value = "/{id}", method = RequestMethod.GET) - @ResponseBody - public Foo findById(@PathVariable("id") final Long id, final HttpServletResponse response) { - final Foo resourceById = RestPreconditions.checkFound(service.findOne(id)); + @RequestMapping(value = "/{id}", method = RequestMethod.GET) + @ResponseBody + public Foo findById(@PathVariable("id") final Long id, final HttpServletResponse response) { + final Foo resourceById = RestPreconditions.checkFound(service.findOne(id)); - eventPublisher.publishEvent(new SingleResourceRetrievedEvent(this, response)); - return resourceById; - } + eventPublisher.publishEvent(new SingleResourceRetrievedEvent(this, response)); + return resourceById; + } - // read - all + // read - all - @RequestMapping(method = RequestMethod.GET) - @ResponseBody - public List findAll() { - return service.findAll(); - } + @RequestMapping(method = RequestMethod.GET) + @ResponseBody + public List findAll() { + return service.findAll(); + } - @RequestMapping(params = { "page", "size" }, method = RequestMethod.GET) - @ResponseBody - public List findPaginated(@RequestParam("page") final int page, @RequestParam("size") final int size, final UriComponentsBuilder uriBuilder, final HttpServletResponse response) { - final Page resultPage = service.findPaginated(page, size); - if (page > resultPage.getTotalPages()) { - throw new MyResourceNotFoundException(); - } - eventPublisher.publishEvent(new PaginatedResultsRetrievedEvent(Foo.class, uriBuilder, response, page, resultPage.getTotalPages(), size)); + @RequestMapping(params = { "page", "size" }, method = RequestMethod.GET) + @ResponseBody + public List findPaginated(@RequestParam("page") final int page, @RequestParam("size") final int size, final UriComponentsBuilder uriBuilder, final HttpServletResponse response) { + final Page resultPage = service.findPaginated(page, size); + if (page > resultPage.getTotalPages()) { + throw new MyResourceNotFoundException(); + } + eventPublisher.publishEvent(new PaginatedResultsRetrievedEvent(Foo.class, uriBuilder, response, page, resultPage.getTotalPages(), size)); - return resultPage.getContent(); - } + return resultPage.getContent(); + } - // write + // write - @RequestMapping(method = RequestMethod.POST) - @ResponseStatus(HttpStatus.CREATED) - @ResponseBody - public Foo create(@RequestBody final Foo resource, final HttpServletResponse response) { - Preconditions.checkNotNull(resource); - final Foo foo = service.create(resource); - final Long idOfCreatedResource = foo.getId(); + @RequestMapping(method = RequestMethod.POST) + @ResponseStatus(HttpStatus.CREATED) + @ResponseBody + public Foo create(@RequestBody final Foo resource, final HttpServletResponse response) { + Preconditions.checkNotNull(resource); + final Foo foo = service.create(resource); + final Long idOfCreatedResource = foo.getId(); - eventPublisher.publishEvent(new ResourceCreatedEvent(this, response, idOfCreatedResource)); + eventPublisher.publishEvent(new ResourceCreatedEvent(this, response, idOfCreatedResource)); - return foo; - } + return foo; + } - @RequestMapping(value = "/{id}", method = RequestMethod.PUT) - @ResponseStatus(HttpStatus.OK) - public void update(@PathVariable("id") final Long id, @RequestBody final Foo resource) { - Preconditions.checkNotNull(resource); - RestPreconditions.checkFound(service.findOne(resource.getId())); - service.update(resource); - } + @RequestMapping(value = "/{id}", method = RequestMethod.PUT) + @ResponseStatus(HttpStatus.OK) + public void update(@PathVariable("id") final Long id, @RequestBody final Foo resource) { + Preconditions.checkNotNull(resource); + RestPreconditions.checkFound(service.findOne(resource.getId())); + service.update(resource); + } - @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) - @ResponseStatus(HttpStatus.OK) - public void delete(@PathVariable("id") final Long id) { - service.deleteById(id); - } + @RequestMapping(value = "/{id}", method = RequestMethod.DELETE) + @ResponseStatus(HttpStatus.OK) + public void delete(@PathVariable("id") final Long id) { + service.deleteById(id); + } - @RequestMapping(method = RequestMethod.HEAD) - @ResponseStatus(HttpStatus.OK) - public void head(final HttpServletResponse resp) { - resp.setContentType(MediaType.APPLICATION_JSON_VALUE); - resp.setHeader("bar", "baz"); - } + @RequestMapping(method = RequestMethod.HEAD) + @ResponseStatus(HttpStatus.OK) + public void head(final HttpServletResponse resp) { + resp.setContentType(MediaType.APPLICATION_JSON_VALUE); + resp.setHeader("bar", "baz"); + } } diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java new file mode 100644 index 0000000000..3e6a6627df --- /dev/null +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/HomeController.java @@ -0,0 +1,14 @@ +package org.baeldung.web.controller; + +import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.RequestMapping; + +@Controller +@RequestMapping(value = "/") +public class HomeController { + + public String index() { + return "homepage"; + } + +} diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java index e83b8cf5ba..bcf0ceb5e6 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/RootController.java @@ -20,65 +20,66 @@ import org.springframework.web.bind.annotation.ResponseStatus; import org.springframework.web.util.UriTemplate; @Controller +@RequestMapping(value = "/auth/") public class RootController { - @Autowired - private IMetricService metricService; + @Autowired + private IMetricService metricService; - @Autowired - private IActuatorMetricService actMetricService; + @Autowired + private IActuatorMetricService actMetricService; - public RootController() { - super(); - } + public RootController() { + super(); + } - // API + // API - // discover + // discover - @RequestMapping(value = "admin", method = RequestMethod.GET) - @ResponseStatus(value = HttpStatus.NO_CONTENT) - public void adminRoot(final HttpServletRequest request, final HttpServletResponse response) { - final String rootUri = request.getRequestURL().toString(); + @RequestMapping(value = "admin", method = RequestMethod.GET) + @ResponseStatus(value = HttpStatus.NO_CONTENT) + public void adminRoot(final HttpServletRequest request, final HttpServletResponse response) { + final String rootUri = request.getRequestURL().toString(); - final URI fooUri = new UriTemplate("{rootUri}/{resource}").expand(rootUri, "foo"); - final String linkToFoo = LinkUtil.createLinkHeader(fooUri.toASCIIString(), "collection"); - response.addHeader("Link", linkToFoo); - } + final URI fooUri = new UriTemplate("{rootUri}/{resource}").expand(rootUri, "foo"); + final String linkToFoo = LinkUtil.createLinkHeader(fooUri.toASCIIString(), "collection"); + response.addHeader("Link", linkToFoo); + } - @RequestMapping(value = "/metric", method = RequestMethod.GET) - @ResponseBody - public Map getMetric() { - return metricService.getFullMetric(); - } + @RequestMapping(value = "/metric", method = RequestMethod.GET) + @ResponseBody + public Map getMetric() { + return metricService.getFullMetric(); + } - @PreAuthorize("hasRole('ROLE_ADMIN')") - @RequestMapping(value = "/status-metric", method = RequestMethod.GET) - @ResponseBody - public Map getStatusMetric() { - return metricService.getStatusMetric(); - } + @PreAuthorize("hasRole('ROLE_ADMIN')") + @RequestMapping(value = "/status-metric", method = RequestMethod.GET) + @ResponseBody + public Map getStatusMetric() { + return metricService.getStatusMetric(); + } - @RequestMapping(value = "/metric-graph", method = RequestMethod.GET) - @ResponseBody - public Object[][] drawMetric() { - final Object[][] result = metricService.getGraphData(); - for (int i = 1; i < result[0].length; i++) { - result[0][i] = result[0][i].toString(); - } - return result; - } + @RequestMapping(value = "/metric-graph", method = RequestMethod.GET) + @ResponseBody + public Object[][] drawMetric() { + final Object[][] result = metricService.getGraphData(); + for (int i = 1; i < result[0].length; i++) { + result[0][i] = result[0][i].toString(); + } + return result; + } - @RequestMapping(value = "/admin/x", method = RequestMethod.GET) - @ResponseBody - public String sampleAdminPage() { - return "Hello"; - } + @RequestMapping(value = "/admin/x", method = RequestMethod.GET) + @ResponseBody + public String sampleAdminPage() { + return "Hello"; + } - @RequestMapping(value = "/my-error-page", method = RequestMethod.GET) - @ResponseBody - public String sampleErrorPage() { - return "Error Occurred"; - } + @RequestMapping(value = "/my-error-page", method = RequestMethod.GET) + @ResponseBody + public String sampleErrorPage() { + return "Error Occurred"; + } } diff --git a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/UserController.java b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/UserController.java index 7c28ed8e80..2228287f4d 100644 --- a/spring-security-rest-full/src/main/java/org/baeldung/web/controller/UserController.java +++ b/spring-security-rest-full/src/main/java/org/baeldung/web/controller/UserController.java @@ -37,96 +37,97 @@ import cz.jirutka.rsql.parser.ast.Node; //@EnableSpringDataWebSupport @Controller +@RequestMapping(value = "/auth/") public class UserController { - @Autowired - private IUserDAO service; + @Autowired + private IUserDAO service; - @Autowired - private UserRepository dao; + @Autowired + private UserRepository dao; - @Autowired - private MyUserRepository myUserRepository; + @Autowired + private MyUserRepository myUserRepository; - public UserController() { - super(); - } + public UserController() { + super(); + } - // API - READ + // API - READ - @RequestMapping(method = RequestMethod.GET, value = "/users") - @ResponseBody - public List findAll(@RequestParam(value = "search", required = false) final String search) { - final List params = new ArrayList(); - if (search != null) { - final Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); - final Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - params.add(new SearchCriteria(matcher.group(1), matcher.group(2), matcher.group(3))); - } - } - return service.searchUser(params); - } + @RequestMapping(method = RequestMethod.GET, value = "/users") + @ResponseBody + public List findAll(@RequestParam(value = "search", required = false) final String search) { + final List params = new ArrayList(); + if (search != null) { + final Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); + final Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + params.add(new SearchCriteria(matcher.group(1), matcher.group(2), matcher.group(3))); + } + } + return service.searchUser(params); + } - @RequestMapping(method = RequestMethod.GET, value = "/users/spec") - @ResponseBody - public List findAllBySpecification(@RequestParam(value = "search") final String search) { - final UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); - final String operationSetExper = Joiner.on("|").join(SearchOperation.SIMPLE_OPERATION_SET); - final Pattern pattern = Pattern.compile("(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); - final Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(4), matcher.group(3), matcher.group(5)); - } + @RequestMapping(method = RequestMethod.GET, value = "/users/spec") + @ResponseBody + public List findAllBySpecification(@RequestParam(value = "search") final String search) { + final UserSpecificationsBuilder builder = new UserSpecificationsBuilder(); + final String operationSetExper = Joiner.on("|").join(SearchOperation.SIMPLE_OPERATION_SET); + final Pattern pattern = Pattern.compile("(\\w+?)(" + operationSetExper + ")(\\p{Punct}?)(\\w+?)(\\p{Punct}?),"); + final Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(4), matcher.group(3), matcher.group(5)); + } - final Specification spec = builder.build(); - return dao.findAll(spec); - } + final Specification spec = builder.build(); + return dao.findAll(spec); + } - @RequestMapping(method = RequestMethod.GET, value = "/myusers") - @ResponseBody - public Iterable findAllByQuerydsl(@RequestParam(value = "search") final String search) { - final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder(); - if (search != null) { - final Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); - final Matcher matcher = pattern.matcher(search + ","); - while (matcher.find()) { - builder.with(matcher.group(1), matcher.group(2), matcher.group(3)); - } - } - final BooleanExpression exp = builder.build(); - return myUserRepository.findAll(exp); - } + @RequestMapping(method = RequestMethod.GET, value = "/myusers") + @ResponseBody + public Iterable findAllByQuerydsl(@RequestParam(value = "search") final String search) { + final MyUserPredicatesBuilder builder = new MyUserPredicatesBuilder(); + if (search != null) { + final Pattern pattern = Pattern.compile("(\\w+?)(:|<|>)(\\w+?),"); + final Matcher matcher = pattern.matcher(search + ","); + while (matcher.find()) { + builder.with(matcher.group(1), matcher.group(2), matcher.group(3)); + } + } + final BooleanExpression exp = builder.build(); + return myUserRepository.findAll(exp); + } - @RequestMapping(method = RequestMethod.GET, value = "/users/rsql") - @ResponseBody - public List findAllByRsql(@RequestParam(value = "search") final String search) { - final Node rootNode = new RSQLParser().parse(search); - final Specification spec = rootNode.accept(new CustomRsqlVisitor()); - return dao.findAll(spec); - } + @RequestMapping(method = RequestMethod.GET, value = "/users/rsql") + @ResponseBody + public List findAllByRsql(@RequestParam(value = "search") final String search) { + final Node rootNode = new RSQLParser().parse(search); + final Specification spec = rootNode.accept(new CustomRsqlVisitor()); + return dao.findAll(spec); + } - @RequestMapping(method = RequestMethod.GET, value = "/api/myusers") - @ResponseBody - public Iterable findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) final Predicate predicate) { - return myUserRepository.findAll(predicate); - } + @RequestMapping(method = RequestMethod.GET, value = "/api/myusers") + @ResponseBody + public Iterable findAllByWebQuerydsl(@QuerydslPredicate(root = MyUser.class) final Predicate predicate) { + return myUserRepository.findAll(predicate); + } - // API - WRITE + // API - WRITE - @RequestMapping(method = RequestMethod.POST, value = "/users") - @ResponseStatus(HttpStatus.CREATED) - public void create(@RequestBody final User resource) { - Preconditions.checkNotNull(resource); - dao.save(resource); - } + @RequestMapping(method = RequestMethod.POST, value = "/users") + @ResponseStatus(HttpStatus.CREATED) + public void create(@RequestBody final User resource) { + Preconditions.checkNotNull(resource); + dao.save(resource); + } - @RequestMapping(method = RequestMethod.POST, value = "/myusers") - @ResponseStatus(HttpStatus.CREATED) - public void addMyUser(@RequestBody final MyUser resource) { - Preconditions.checkNotNull(resource); - myUserRepository.save(resource); + @RequestMapping(method = RequestMethod.POST, value = "/myusers") + @ResponseStatus(HttpStatus.CREATED) + public void addMyUser(@RequestBody final MyUser resource) { + Preconditions.checkNotNull(resource); + myUserRepository.save(resource); - } + } } diff --git a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java index 3af91b82a2..35b840a649 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfAbstractIntegrationTest.java @@ -23,26 +23,30 @@ import com.fasterxml.jackson.databind.ObjectMapper; @WebAppConfiguration public class CsrfAbstractIntegrationTest { - @Autowired - private WebApplicationContext context; + @Autowired + private WebApplicationContext context; - @Autowired - private Filter springSecurityFilterChain; + @Autowired + private Filter springSecurityFilterChain; - protected MockMvc mvc; + protected MockMvc mvc; - // + // - @Before - public void setup() { - mvc = MockMvcBuilders.webAppContextSetup(context).addFilters(springSecurityFilterChain).build(); - } + @Before + public void setup() { + mvc = MockMvcBuilders.webAppContextSetup(context).addFilters(springSecurityFilterChain).build(); + } - protected RequestPostProcessor testUser() { - return user("user").password("userPass").roles("USER"); - } + protected RequestPostProcessor testUser() { + return user("user").password("userPass").roles("USER"); + } - protected String createFoo() throws JsonProcessingException { - return new ObjectMapper().writeValueAsString(new Foo(randomAlphabetic(6))); - } + protected RequestPostProcessor testAdmin() { + return user("admin").password("adminPass").roles("USER", "ADMIN"); + } + + protected String createFoo() throws JsonProcessingException { + return new ObjectMapper().writeValueAsString(new Foo(randomAlphabetic(6))); + } } diff --git a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfDisabledIntegrationTest.java b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfDisabledIntegrationTest.java index 50b8ae3b44..1f5cf078f3 100644 --- a/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfDisabledIntegrationTest.java +++ b/spring-security-rest-full/src/test/java/org/baeldung/security/csrf/CsrfDisabledIntegrationTest.java @@ -1,5 +1,6 @@ package org.baeldung.security.csrf; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -13,14 +14,33 @@ import org.springframework.test.context.ContextConfiguration; @ContextConfiguration(classes = { SecurityWithoutCsrfConfig.class, PersistenceConfig.class, WebConfig.class }) public class CsrfDisabledIntegrationTest extends CsrfAbstractIntegrationTest { - @Test - public void givenNotAuth_whenAddFoo_thenUnauthorized() throws Exception { - mvc.perform(post("/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo())).andExpect(status().isUnauthorized()); - } + @Test + public void givenNotAuth_whenAddFoo_thenUnauthorized() throws Exception { + mvc.perform(post("/auth/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo())).andExpect(status().isUnauthorized()); + } - @Test - public void givenAuth_whenAddFoo_thenCreated() throws Exception { - mvc.perform(post("/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo()).with(testUser())).andExpect(status().isCreated()); - } + @Test + public void givenAuth_whenAddFoo_thenCreated() throws Exception { + mvc.perform(post("/auth/foos").contentType(MediaType.APPLICATION_JSON).content(createFoo()).with(testUser())).andExpect(status().isCreated()); + } + + @Test + public void accessMainPageWithoutAuthorization() throws Exception { + mvc.perform(get("/graph.html").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isOk()); + } + + @Test + public void accessOtherPages() throws Exception { + mvc.perform(get("/auth/transfer").contentType(MediaType.APPLICATION_JSON).param("accountNo", "1").param("amount", "100")) + .andExpect(status().isUnauthorized()); // without authorization + mvc.perform(get("/auth/transfer").contentType(MediaType.APPLICATION_JSON).param("accountNo", "1").param("amount", "100").with(testUser())) + .andExpect(status().isOk()); // with authorization + } + + @Test + public void accessAdminPage() throws Exception { + mvc.perform(get("/auth/admin/x").contentType(MediaType.APPLICATION_JSON)).andExpect(status().isUnauthorized()); //without authorization + mvc.perform(get("/auth/admin/x").contentType(MediaType.APPLICATION_JSON).with(testAdmin())).andExpect(status().isOk()); //with authorization + } } From b5ce0e9ba05a4017e98c02b515a058d83ff39149 Mon Sep 17 00:00:00 2001 From: egimaben Date: Thu, 21 Jul 2016 00:20:44 +0300 Subject: [PATCH 07/24] fixed failing test --- .../src/test/java/com/baeldung/restassured/RestAssuredTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java index a88ef2efc0..05d0a4d59c 100644 --- a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java @@ -55,7 +55,7 @@ public class RestAssuredTest { @Test public void givenUrl_whenJsonResponseHasArrayWithGivenValuesUnderKey_thenCorrect() { get("/events?id=390").then().assertThat() - .body("odds.price", hasItems(1.30f, 5.25f, 2.70f, 1.20f)); + .body("odds.price", hasItems("1.30", "5.25", "2.70", "1.20")); } @Test From 4bc3153fc076ac7bb62141be2d923ad6ec2c5229 Mon Sep 17 00:00:00 2001 From: Alex Theedom Date: Wed, 20 Jul 2016 23:36:12 +0100 Subject: [PATCH 08/24] Config changes to log4j and a minor code change --- rest-assured-tutorial/pom.xml | 4 ++-- .../test/java/com/baeldung/restassured/RestAssuredTest.java | 2 +- rest-assured-tutorial/src/test/resources/log4j.properties | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/rest-assured-tutorial/pom.xml b/rest-assured-tutorial/pom.xml index 43072d3094..0d5a73d075 100644 --- a/rest-assured-tutorial/pom.xml +++ b/rest-assured-tutorial/pom.xml @@ -12,8 +12,8 @@ maven-compiler-plugin 3.3 - 7 - 7 + 8 + 8 diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java index 05d0a4d59c..e971efe3cb 100644 --- a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java @@ -99,7 +99,7 @@ public class RestAssuredTest { } private static String getEventJson() { - return Util.inputStreamToString(new RestAssuredTest().getClass() + return Util.inputStreamToString(RestAssuredTest.class .getResourceAsStream("/event_0.json")); } diff --git a/rest-assured-tutorial/src/test/resources/log4j.properties b/rest-assured-tutorial/src/test/resources/log4j.properties index e4b76524e8..d3c6b9e783 100644 --- a/rest-assured-tutorial/src/test/resources/log4j.properties +++ b/rest-assured-tutorial/src/test/resources/log4j.properties @@ -1,12 +1,11 @@ -## Logger configure file for myproject -log.dir=C:/ProgramData/radixbase/ +## Logger configure datestamp=yyyy-MM-dd HH:mm:ss log4j.rootLogger=TRACE, file, console log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.maxFileSize=1GB log4j.appender.file.maxBackupIndex=5 -log4j.appender.file.File=log/mydebug.log +log4j.appender.file.File=log/rest-assured.log log4j.appender.file.threshold=TRACE log4j.appender.file.layout=org.apache.log4j.PatternLayout log4j.appender.file.layout.ConversionPattern=%d{${datestamp}} %5p: [%c] - %m%n From 864839a8415e03fd02d6f35792c2e3646090fbd3 Mon Sep 17 00:00:00 2001 From: Thai Nguyen Date: Thu, 21 Jul 2016 09:20:48 +0700 Subject: [PATCH 09/24] Changes the name of the SpringBus bean --- .../java/com/baeldung/cxf/spring/ServiceConfiguration.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java index 0d150532bf..f1fac579ab 100644 --- a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java +++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java @@ -2,6 +2,7 @@ package com.baeldung.cxf.spring; import javax.xml.ws.Endpoint; +import org.apache.cxf.Bus; import org.apache.cxf.bus.spring.SpringBus; import org.apache.cxf.jaxws.EndpointImpl; import org.springframework.context.annotation.Bean; @@ -9,10 +10,10 @@ import org.springframework.context.annotation.Configuration; @Configuration public class ServiceConfiguration { - @Bean + @Bean(name = Bus.DEFAULT_BUS_ID) public SpringBus springBus() { return new SpringBus(); - } + } @Bean public Endpoint endpoint() { From deaf809ec776a17cb4bcd1e72456d2af0ba4fbff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Fern=C3=A1ndez=20Gonz=C3=A1lez?= Date: Fri, 22 Jul 2016 10:16:50 +0200 Subject: [PATCH 10/24] Adding new article to readme after article going live (#522) * Add new module for mocks comparison. * Add sources for testing. * Changes on testCase. * Enter some tests for mockito. * More tests for Mockito. * Even more tests. * Add the rest of the mocking libraries. * Javadoc on test. * Test bare bones for EasyMock. * Fist kind of test and setup. * Add tests using EasyMock with a change on LoginService. * Create LoginControllerTest.java * Test setup * [JMockit] No method called test. * [JMockit] Two methods called test. * [JMockit] One method called test. * [JMockit] Exception mock test * [JMockit] Mocked object to pass around test. * [JMockit] Custom matcher test. * [JMockit] Partial mocking test. * [JMockit] Fix with IDE. * Not stubs. Mocks. MOCKS!!! * Remove unnecesary import. * Use correct encoding. Was having problems with buildings. * Remove failing module. * Create new module mocks and move mock-comparisons there. * Add jmockit module. * Add model class. * Add collaborator class. * Add performer class. * Add performer test. * Fix * Add interface for tests. * Test for any. * Test for with. * Test for null. * Test for times. * Test for arg that. * Test for result and returns. * Test for delegate. * Add verifications to any tests. * Add verifications to with test. * Add verification examples to methods using null. * Add verifications to methods using times. * Formatting. * Compress tests and fix one test. * Adding new article to readme. --- mocks/jmockit/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/mocks/jmockit/README.md b/mocks/jmockit/README.md index c310463c26..d04a07fdc5 100644 --- a/mocks/jmockit/README.md +++ b/mocks/jmockit/README.md @@ -5,3 +5,4 @@ ### Relevant Articles: - [JMockit 101](http://www.baeldung.com/jmockit-101) +- [A Guide to JMockit Expectations](http://www.baeldung.com/jmockit-expectations) From 1e14ac7028af0fbd86e2fd5b937cde15b123b0d6 Mon Sep 17 00:00:00 2001 From: egimaben Date: Fri, 22 Jul 2016 22:14:48 +0300 Subject: [PATCH 11/24] added xmlunit 2.x tutorial project --- xmlunit2-tutorial/README.md | 0 xmlunit2-tutorial/pom.xml | 46 +++ .../IgnoreAttributeDifferenceEvaluator.java | 31 ++ .../com/baeldung/xmlunit/XMLUnitTest.java | 290 ++++++++++++++++++ .../src/test/resources/control.xml | 4 + .../src/test/resources/students.xml | 11 + .../src/test/resources/students.xsd | 18 ++ .../test/resources/students_with_error.xml | 12 + .../src/test/resources/teachers.xml | 10 + xmlunit2-tutorial/src/test/resources/test.xml | 4 + 10 files changed, 426 insertions(+) create mode 100644 xmlunit2-tutorial/README.md create mode 100644 xmlunit2-tutorial/pom.xml create mode 100644 xmlunit2-tutorial/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java create mode 100644 xmlunit2-tutorial/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java create mode 100644 xmlunit2-tutorial/src/test/resources/control.xml create mode 100644 xmlunit2-tutorial/src/test/resources/students.xml create mode 100644 xmlunit2-tutorial/src/test/resources/students.xsd create mode 100644 xmlunit2-tutorial/src/test/resources/students_with_error.xml create mode 100644 xmlunit2-tutorial/src/test/resources/teachers.xml create mode 100644 xmlunit2-tutorial/src/test/resources/test.xml diff --git a/xmlunit2-tutorial/README.md b/xmlunit2-tutorial/README.md new file mode 100644 index 0000000000..e69de29bb2 diff --git a/xmlunit2-tutorial/pom.xml b/xmlunit2-tutorial/pom.xml new file mode 100644 index 0000000000..b4cb684f65 --- /dev/null +++ b/xmlunit2-tutorial/pom.xml @@ -0,0 +1,46 @@ + + 4.0.0 + com.baeldung + xmlunit2-tutorial + 1.0 + XMLUnit-2 + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.3 + + 7 + 7 + + + + + + + junit + junit + 4.3 + test + + + org.hamcrest + hamcrest-all + 1.3 + + + org.xmlunit + xmlunit-matchers + 2.2.1 + + + + org.xmlunit + xmlunit-core + 2.2.1 + + + + diff --git a/xmlunit2-tutorial/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java b/xmlunit2-tutorial/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java new file mode 100644 index 0000000000..2f644e0114 --- /dev/null +++ b/xmlunit2-tutorial/src/main/java/com/baeldung/xmlunit/IgnoreAttributeDifferenceEvaluator.java @@ -0,0 +1,31 @@ +package com.baeldung.xmlunit; + +import org.w3c.dom.Attr; +import org.w3c.dom.Node; +import org.xmlunit.diff.Comparison; +import org.xmlunit.diff.ComparisonResult; +import org.xmlunit.diff.DifferenceEvaluator; + +public class IgnoreAttributeDifferenceEvaluator implements DifferenceEvaluator { + + private String attributeName; + + public IgnoreAttributeDifferenceEvaluator(String attributeName) { + this.attributeName = attributeName; + } + + @Override + public ComparisonResult evaluate(Comparison comparison, + ComparisonResult outcome) { + if (outcome == ComparisonResult.EQUAL) + return outcome; + final Node controlNode = comparison.getControlDetails().getTarget(); + if (controlNode instanceof Attr) { + Attr attr = (Attr) controlNode; + if (attr.getName().equals(attributeName)) { + return ComparisonResult.SIMILAR; + } + } + return outcome; + } +} diff --git a/xmlunit2-tutorial/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java b/xmlunit2-tutorial/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java new file mode 100644 index 0000000000..d0e099e591 --- /dev/null +++ b/xmlunit2-tutorial/src/test/java/com/baeldung/xmlunit/XMLUnitTest.java @@ -0,0 +1,290 @@ +package com.baeldung.xmlunit; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.core.IsNot.not; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.xmlunit.matchers.CompareMatcher.isIdenticalTo; +import static org.xmlunit.matchers.CompareMatcher.isSimilarTo; +import static org.xmlunit.matchers.HasXPathMatcher.hasXPath; + +import java.io.File; +import java.util.Iterator; + +import org.junit.Test; +import org.w3c.dom.NamedNodeMap; +import org.w3c.dom.Node; +import org.xmlunit.builder.DiffBuilder; +import org.xmlunit.builder.Input; +import org.xmlunit.diff.ComparisonControllers; +import org.xmlunit.diff.DefaultNodeMatcher; +import org.xmlunit.diff.Diff; +import org.xmlunit.diff.Difference; +import org.xmlunit.diff.ElementSelectors; +import org.xmlunit.validation.Languages; +import org.xmlunit.validation.ValidationProblem; +import org.xmlunit.validation.ValidationResult; +import org.xmlunit.validation.Validator; +import org.xmlunit.xpath.JAXPXPathEngine; + +public class XMLUnitTest { + @Test + public void givenWrongXml_whenValidateFailsAgainstXsd_thenCorrect() { + Validator v = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(Input.fromStream( + new XMLUnitTest().getClass().getResourceAsStream( + "/students.xsd")).build()); + ValidationResult r = v.validateInstance(Input.fromStream( + new XMLUnitTest().getClass().getResourceAsStream( + "/students_with_error.xml")).build()); + assertFalse(r.isValid()); + } + + @Test + public void givenXmlWithErrors_whenReturnsValidationProblems_thenCorrect() { + Validator v = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(Input.fromStream( + new XMLUnitTest().getClass().getResourceAsStream( + "/students.xsd")).build()); + ValidationResult r = v.validateInstance(Input.fromStream( + new XMLUnitTest().getClass().getResourceAsStream( + "/students_with_error.xml")).build()); + Iterator probs = r.getProblems().iterator(); + int count = 0; + while (probs.hasNext()) { + count++; + probs.next().toString(); + } + assertTrue(count > 0); + } + + @Test + public void givenXml_whenValidatesAgainstXsd_thenCorrect() { + Validator v = Validator.forLanguage(Languages.W3C_XML_SCHEMA_NS_URI); + v.setSchemaSource(Input.fromStream( + new XMLUnitTest().getClass().getResourceAsStream( + "/students.xsd")).build()); + ValidationResult r = v.validateInstance(Input.fromStream( + new XMLUnitTest().getClass().getResourceAsStream( + "/students.xml")).build()); + Iterator probs = r.getProblems().iterator(); + while (probs.hasNext()) { + System.out.println(probs.next().toString()); + } + assertTrue(r.isValid()); + } + + @Test + public void givenXPath_whenAbleToRetrieveNodes_thenCorrect() { + ClassLoader classLoader = getClass().getClassLoader(); + + Iterable i = new JAXPXPathEngine().selectNodes( + "//teacher", + Input.fromFile( + new File(classLoader.getResource("teachers.xml") + .getFile())).build()); + assertNotNull(i); + int count = 0; + for (Iterator it = i.iterator(); it.hasNext();) { + count++; + Node node = it.next(); + assertEquals("teacher", node.getNodeName()); + NamedNodeMap map = node.getAttributes(); + assertEquals("department", map.item(0).getNodeName()); + assertEquals("id", map.item(1).getNodeName()); + assertEquals("teacher", node.getNodeName()); + } + assertEquals(2, count); + } + + @Test + public void givenXmlSource_whenAbleToValidateExistingXPath_thenCorrect() { + ClassLoader classLoader = getClass().getClassLoader(); + assertThat(Input.fromFile(new File(classLoader.getResource( + "teachers.xml").getFile())), hasXPath("//teachers")); + assertThat(Input.fromFile(new File(classLoader.getResource( + "teachers.xml").getFile())), hasXPath("//teacher")); + assertThat(Input.fromFile(new File(classLoader.getResource( + "teachers.xml").getFile())), hasXPath("//subject")); + assertThat(Input.fromFile(new File(classLoader.getResource( + "teachers.xml").getFile())), hasXPath("//@department")); + } + + @Test + public void givenXmlSource_whenFailsToValidateInExistentXPath_thenCorrect() { + ClassLoader classLoader = getClass().getClassLoader(); + + assertThat(Input.fromFile(new File(classLoader.getResource( + "teachers.xml").getFile())), not(hasXPath("//sujet"))); + } + + @Test + public void given2XMLs_whenSimilarWithDiff_thenCorrect() throws Exception { + String myControlXML = "3false"; + String myTestXML = "false3"; + + Diff myDiffSimilar = DiffBuilder + .compare(myControlXML) + .withTest(myTestXML) + .withNodeMatcher( + new DefaultNodeMatcher(ElementSelectors.byName)) + .checkForSimilar().build(); + assertFalse("XML similar " + myDiffSimilar.toString(), + myDiffSimilar.hasDifferences()); + + } + + @Test + public void given2XMLsWithDifferences_whenTestsSimilarWithDifferenceEvaluator_thenCorrect() { + final String control = ""; + final String test = ""; + Diff myDiff = DiffBuilder + .compare(control) + .withTest(test) + .withDifferenceEvaluator( + new IgnoreAttributeDifferenceEvaluator("attr")) + .checkForSimilar().build(); + + assertFalse(myDiff.toString(), myDiff.hasDifferences()); + } + + @Test + public void given2XMLsWithDifferences_whenTestsDifferentWithoutDifferenceEvaluator_thenCorrect() { + final String control = ""; + final String test = ""; + + Diff myDiff = DiffBuilder.compare(control).withTest(test) + .checkForSimilar().build(); + + assertTrue(myDiff.toString(), myDiff.hasDifferences()); + } + + @Test + public void given2XMLS_whenSimilarWithCustomElementSelector_thenCorrect() { + String controlXml = "3false"; + String testXml = "false3"; + assertThat( + testXml, + isSimilarTo(controlXml).withNodeMatcher( + new DefaultNodeMatcher(ElementSelectors.byName))); + + } + + @Test + public void givenFileSourceAsObject_whenAbleToInput_thenCorrect() { + ClassLoader classLoader = getClass().getClassLoader(); + assertThat(Input.from(new File(classLoader.getResource("test.xml") + .getFile())), isSimilarTo(Input.from(new File(classLoader + .getResource("control.xml").getFile())))); + + } + + @Test + public void givenStreamAsSource_whenAbleToInput_thenCorrect() { + assertThat(Input.fromStream(new XMLUnitTest().getClass() + .getResourceAsStream("/test.xml")), + isSimilarTo(Input.fromStream(new XMLUnitTest().getClass() + .getResourceAsStream("/control.xml")))); + + } + + @Test + public void givenStreamAsObject_whenAbleToInput_thenCorrect() { + assertThat(Input.from(new XMLUnitTest().getClass().getResourceAsStream( + "/test.xml")), isSimilarTo(Input.from(new XMLUnitTest() + .getClass().getResourceAsStream("/control.xml")))); + + } + + @Test + public void givenStringSourceAsObject_whenAbleToInput_thenCorrect() { + assertThat( + Input.from("3false"), + isSimilarTo(Input + .from("3false"))); + + } + + @Test + public void givenFileSource_whenAbleToInput_thenCorrect() { + ClassLoader classLoader = getClass().getClassLoader(); + String testPath = classLoader.getResource("test.xml").getPath(); + String controlPath = classLoader.getResource("control.xml").getPath(); + assertThat(Input.fromFile(testPath), + isSimilarTo(Input.fromFile(controlPath))); + + } + + @Test + public void givenStringSource_whenAbleToInput_thenCorrect() { + String controlXml = "3false"; + String testXml = "3false"; + assertThat(Input.fromString(testXml), + isSimilarTo(Input.fromString(controlXml))); + + } + + @Test + public void givenSource_whenAbleToInput_thenCorrect() { + String controlXml = "3false"; + String testXml = "3false"; + assertThat(Input.fromString(testXml), + isSimilarTo(Input.fromString(controlXml))); + + } + + @Test + public void given2XMLS_whenIdentical_thenCorrect() { + String controlXml = "3false"; + String testXml = "3false"; + assertThat(testXml, isIdenticalTo(controlXml)); + + } + + @Test + public void given2XMLSWithSimilarNodesButDifferentSequence_whenNotIdentical_thenCorrect() { + String controlXml = "3false"; + String testXml = "false3"; + assertThat(testXml, not(isIdenticalTo(controlXml))); + + } + + @Test + public void given2XMLS_whenGeneratesDifferences_thenCorrect() + throws Exception { + String controlXml = "3false"; + String testXml = "false3"; + Diff myDiff = DiffBuilder.compare(controlXml).withTest(testXml).build(); + Iterator iter = myDiff.getDifferences().iterator(); + int size = 0; + while (iter.hasNext()) { + iter.next().toString(); + size++; + } + assertThat(size, greaterThan(1)); + } + + @Test + public void given2XMLS_whenGeneratesOneDifference_thenCorrect() + throws Exception { + String myControlXML = "3false"; + String myTestXML = "false3"; + Diff myDiff = DiffBuilder + .compare(myControlXML) + .withTest(myTestXML) + .withComparisonController( + ComparisonControllers.StopWhenDifferent).build(); + Iterator iter = myDiff.getDifferences().iterator(); + int size = 0; + while (iter.hasNext()) { + iter.next().toString(); + size++; + } + assertThat(size, equalTo(1)); + } + +} diff --git a/xmlunit2-tutorial/src/test/resources/control.xml b/xmlunit2-tutorial/src/test/resources/control.xml new file mode 100644 index 0000000000..afc0f53f91 --- /dev/null +++ b/xmlunit2-tutorial/src/test/resources/control.xml @@ -0,0 +1,4 @@ + + 3 + false + \ No newline at end of file diff --git a/xmlunit2-tutorial/src/test/resources/students.xml b/xmlunit2-tutorial/src/test/resources/students.xml new file mode 100644 index 0000000000..413e73fd07 --- /dev/null +++ b/xmlunit2-tutorial/src/test/resources/students.xml @@ -0,0 +1,11 @@ + + + + Rajiv + 18 + + + Candie + 19 + + \ No newline at end of file diff --git a/xmlunit2-tutorial/src/test/resources/students.xsd b/xmlunit2-tutorial/src/test/resources/students.xsd new file mode 100644 index 0000000000..15b10279f9 --- /dev/null +++ b/xmlunit2-tutorial/src/test/resources/students.xsd @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/xmlunit2-tutorial/src/test/resources/students_with_error.xml b/xmlunit2-tutorial/src/test/resources/students_with_error.xml new file mode 100644 index 0000000000..e9ce77faf0 --- /dev/null +++ b/xmlunit2-tutorial/src/test/resources/students_with_error.xml @@ -0,0 +1,12 @@ + + + + Rajiv + 18 + + + + Candie + 19 + + \ No newline at end of file diff --git a/xmlunit2-tutorial/src/test/resources/teachers.xml b/xmlunit2-tutorial/src/test/resources/teachers.xml new file mode 100644 index 0000000000..9c073d5a38 --- /dev/null +++ b/xmlunit2-tutorial/src/test/resources/teachers.xml @@ -0,0 +1,10 @@ + + + math + physics + + + political education + english + + \ No newline at end of file diff --git a/xmlunit2-tutorial/src/test/resources/test.xml b/xmlunit2-tutorial/src/test/resources/test.xml new file mode 100644 index 0000000000..afc0f53f91 --- /dev/null +++ b/xmlunit2-tutorial/src/test/resources/test.xml @@ -0,0 +1,4 @@ + + 3 + false + \ No newline at end of file From a6ef10a92530fa74da0340932a88b90fa56c5dcb Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Fri, 15 Jul 2016 01:51:17 +0300 Subject: [PATCH 12/24] Add missing modules and clean up --- pom.xml | 20 +++- spring-scurity-custom-permission/README.MD | 2 - ...e.wst.jsdt.core.javascriptValidator.launch | 7 -- .../.settings/.jsdtscope | 5 - .../.settings/org.eclipse.jdt.core.prefs | 95 ------------------- .../.settings/org.eclipse.jdt.ui.prefs | 55 ----------- .../.settings/org.eclipse.m2e.core.prefs | 4 - .../.settings/org.eclipse.m2e.wtp.prefs | 2 - .../org.eclipse.wst.common.component | 10 -- ....eclipse.wst.common.project.facet.core.xml | 5 - ...rg.eclipse.wst.jsdt.ui.superType.container | 1 - .../org.eclipse.wst.jsdt.ui.superType.name | 1 - .../org.eclipse.wst.validation.prefs | 15 --- .../org.eclipse.wst.ws.service.policy.prefs | 2 - webjars/{webjarsdemo => }/pom.xml | 0 .../java/com/baeldung/TestController.java | 0 .../com/baeldung/WebjarsdemoApplication.java | 0 .../src/main/resources/templates/index.html | 0 .../baeldung/WebjarsdemoApplicationTests.java | 0 19 files changed, 19 insertions(+), 205 deletions(-) delete mode 100644 spring-scurity-custom-permission/README.MD delete mode 100644 spring-security-basic-auth/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch delete mode 100644 spring-security-basic-auth/.settings/.jsdtscope delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.jdt.core.prefs delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.jdt.ui.prefs delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.m2e.core.prefs delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.m2e.wtp.prefs delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.wst.common.component delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.wst.common.project.facet.core.xml delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.container delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.name delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.wst.validation.prefs delete mode 100644 spring-security-basic-auth/.settings/org.eclipse.wst.ws.service.policy.prefs rename webjars/{webjarsdemo => }/pom.xml (100%) rename webjars/{webjarsdemo => }/src/main/java/com/baeldung/TestController.java (100%) rename webjars/{webjarsdemo => }/src/main/java/com/baeldung/WebjarsdemoApplication.java (100%) rename webjars/{webjarsdemo => }/src/main/resources/templates/index.html (100%) rename webjars/{webjarsdemo => }/src/test/java/com/baeldung/WebjarsdemoApplicationTests.java (100%) diff --git a/pom.xml b/pom.xml index 82cf85208c..de18c907b3 100644 --- a/pom.xml +++ b/pom.xml @@ -15,8 +15,13 @@ assertj apache-cxf + apache-fop core-java core-java-8 + + dependency-injection + gatling + gson guava @@ -28,7 +33,10 @@ javaxval jjwt jooq-spring + jpa-storedprocedure + json json-path + junit5 mockito mocks jee7schedule @@ -41,13 +49,18 @@ spring-all spring-apache-camel + spring-autowire spring-batch spring-boot spring-controller spring-data-cassandra + spring-data-couchbase-2 + spring-data-couchbase-2b spring-data-elasticsearch + spring-data-neo4j spring-data-mongodb spring-data-redis + spring-data-rest spring-exceptions spring-freemarker spring-hibernate3 @@ -61,9 +74,12 @@ spring-openid spring-protobuf spring-quartz + spring-spel spring-rest + spring-rest-docs spring-security-basic-auth + spring-security-custom-permission spring-security-mvc-custom spring-security-mvc-digest-auth spring-security-mvc-ldap @@ -81,9 +97,11 @@ xml lombok redis - + webjars + mutation-testing spring-mvc-velocity + xstream diff --git a/spring-scurity-custom-permission/README.MD b/spring-scurity-custom-permission/README.MD deleted file mode 100644 index 8fb14fa522..0000000000 --- a/spring-scurity-custom-permission/README.MD +++ /dev/null @@ -1,2 +0,0 @@ -###The Course -The "Learn Spring Security" Classes: http://bit.ly/learnspringsecurity diff --git a/spring-security-basic-auth/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch b/spring-security-basic-auth/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch deleted file mode 100644 index 627021fb96..0000000000 --- a/spring-security-basic-auth/.externalToolBuilders/org.eclipse.wst.jsdt.core.javascriptValidator.launch +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - diff --git a/spring-security-basic-auth/.settings/.jsdtscope b/spring-security-basic-auth/.settings/.jsdtscope deleted file mode 100644 index 7b3f0c8b9f..0000000000 --- a/spring-security-basic-auth/.settings/.jsdtscope +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/spring-security-basic-auth/.settings/org.eclipse.jdt.core.prefs b/spring-security-basic-auth/.settings/org.eclipse.jdt.core.prefs deleted file mode 100644 index fb671a82a6..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.jdt.core.prefs +++ /dev/null @@ -1,95 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore -org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull -org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault -org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable -org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled -org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 -org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve -org.eclipse.jdt.core.compiler.compliance=1.8 -org.eclipse.jdt.core.compiler.debug.lineNumber=generate -org.eclipse.jdt.core.compiler.debug.localVariable=generate -org.eclipse.jdt.core.compiler.debug.sourceFile=generate -org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning -org.eclipse.jdt.core.compiler.problem.assertIdentifier=error -org.eclipse.jdt.core.compiler.problem.autoboxing=ignore -org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning -org.eclipse.jdt.core.compiler.problem.deadCode=warning -org.eclipse.jdt.core.compiler.problem.deprecation=warning -org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled -org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled -org.eclipse.jdt.core.compiler.problem.discouragedReference=warning -org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore -org.eclipse.jdt.core.compiler.problem.enumIdentifier=error -org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=ignore -org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore -org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled -org.eclipse.jdt.core.compiler.problem.fieldHiding=error -org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning -org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning -org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning -org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled -org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning -org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore -org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore -org.eclipse.jdt.core.compiler.problem.localVariableHiding=error -org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning -org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore -org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled -org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore -org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled -org.eclipse.jdt.core.compiler.problem.missingSerialVersion=ignore -org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore -org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning -org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning -org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore -org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error -org.eclipse.jdt.core.compiler.problem.nullReference=warning -org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error -org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning -org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning -org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore -org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore -org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore -org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore -org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning -org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning -org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore -org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=ignore -org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore -org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore -org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled -org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning -org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled -org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled -org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore -org.eclipse.jdt.core.compiler.problem.typeParameterHiding=error -org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled -org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning -org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning -org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore -org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning -org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore -org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore -org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled -org.eclipse.jdt.core.compiler.problem.unusedImport=warning -org.eclipse.jdt.core.compiler.problem.unusedLabel=warning -org.eclipse.jdt.core.compiler.problem.unusedLocal=warning -org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore -org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled -org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled -org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning -org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning -org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning -org.eclipse.jdt.core.compiler.source=1.8 diff --git a/spring-security-basic-auth/.settings/org.eclipse.jdt.ui.prefs b/spring-security-basic-auth/.settings/org.eclipse.jdt.ui.prefs deleted file mode 100644 index 471e9b0d81..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.jdt.ui.prefs +++ /dev/null @@ -1,55 +0,0 @@ -#Sat Jan 21 23:04:06 EET 2012 -eclipse.preferences.version=1 -editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true -sp_cleanup.add_default_serial_version_id=true -sp_cleanup.add_generated_serial_version_id=false -sp_cleanup.add_missing_annotations=true -sp_cleanup.add_missing_deprecated_annotations=true -sp_cleanup.add_missing_methods=false -sp_cleanup.add_missing_nls_tags=false -sp_cleanup.add_missing_override_annotations=true -sp_cleanup.add_missing_override_annotations_interface_methods=true -sp_cleanup.add_serial_version_id=false -sp_cleanup.always_use_blocks=true -sp_cleanup.always_use_parentheses_in_expressions=true -sp_cleanup.always_use_this_for_non_static_field_access=false -sp_cleanup.always_use_this_for_non_static_method_access=false -sp_cleanup.convert_to_enhanced_for_loop=true -sp_cleanup.correct_indentation=true -sp_cleanup.format_source_code=true -sp_cleanup.format_source_code_changes_only=true -sp_cleanup.make_local_variable_final=true -sp_cleanup.make_parameters_final=true -sp_cleanup.make_private_fields_final=false -sp_cleanup.make_type_abstract_if_missing_method=false -sp_cleanup.make_variable_declarations_final=true -sp_cleanup.never_use_blocks=false -sp_cleanup.never_use_parentheses_in_expressions=false -sp_cleanup.on_save_use_additional_actions=true -sp_cleanup.organize_imports=true -sp_cleanup.qualify_static_field_accesses_with_declaring_class=false -sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true -sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true -sp_cleanup.qualify_static_member_accesses_with_declaring_class=true -sp_cleanup.qualify_static_method_accesses_with_declaring_class=false -sp_cleanup.remove_private_constructors=true -sp_cleanup.remove_trailing_whitespaces=true -sp_cleanup.remove_trailing_whitespaces_all=true -sp_cleanup.remove_trailing_whitespaces_ignore_empty=false -sp_cleanup.remove_unnecessary_casts=true -sp_cleanup.remove_unnecessary_nls_tags=false -sp_cleanup.remove_unused_imports=true -sp_cleanup.remove_unused_local_variables=false -sp_cleanup.remove_unused_private_fields=true -sp_cleanup.remove_unused_private_members=false -sp_cleanup.remove_unused_private_methods=true -sp_cleanup.remove_unused_private_types=true -sp_cleanup.sort_members=false -sp_cleanup.sort_members_all=false -sp_cleanup.use_blocks=false -sp_cleanup.use_blocks_only_for_return_and_throw=false -sp_cleanup.use_parentheses_in_expressions=false -sp_cleanup.use_this_for_non_static_field_access=true -sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true -sp_cleanup.use_this_for_non_static_method_access=true -sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true diff --git a/spring-security-basic-auth/.settings/org.eclipse.m2e.core.prefs b/spring-security-basic-auth/.settings/org.eclipse.m2e.core.prefs deleted file mode 100644 index f897a7f1cb..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.m2e.core.prefs +++ /dev/null @@ -1,4 +0,0 @@ -activeProfiles= -eclipse.preferences.version=1 -resolveWorkspaceProjects=true -version=1 diff --git a/spring-security-basic-auth/.settings/org.eclipse.m2e.wtp.prefs b/spring-security-basic-auth/.settings/org.eclipse.m2e.wtp.prefs deleted file mode 100644 index ef86089622..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.m2e.wtp.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.m2e.wtp.enabledProjectSpecificPrefs=false diff --git a/spring-security-basic-auth/.settings/org.eclipse.wst.common.component b/spring-security-basic-auth/.settings/org.eclipse.wst.common.component deleted file mode 100644 index 9a8276c85b..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.wst.common.component +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/spring-security-basic-auth/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-security-basic-auth/.settings/org.eclipse.wst.common.project.facet.core.xml deleted file mode 100644 index f5888c1411..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.wst.common.project.facet.core.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - - - diff --git a/spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.container b/spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.container deleted file mode 100644 index 3bd5d0a480..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.container +++ /dev/null @@ -1 +0,0 @@ -org.eclipse.wst.jsdt.launching.baseBrowserLibrary \ No newline at end of file diff --git a/spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.name b/spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.name deleted file mode 100644 index 05bd71b6ec..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.wst.jsdt.ui.superType.name +++ /dev/null @@ -1 +0,0 @@ -Window \ No newline at end of file diff --git a/spring-security-basic-auth/.settings/org.eclipse.wst.validation.prefs b/spring-security-basic-auth/.settings/org.eclipse.wst.validation.prefs deleted file mode 100644 index 0d0aee4f72..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.wst.validation.prefs +++ /dev/null @@ -1,15 +0,0 @@ -DELEGATES_PREFERENCE=delegateValidatorList -USER_BUILD_PREFERENCE=enabledBuildValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; -USER_MANUAL_PREFERENCE=enabledManualValidatorListorg.eclipse.jst.j2ee.internal.classpathdep.ClasspathDependencyValidator; -USER_PREFERENCE=overrideGlobalPreferencestruedisableAllValidationfalseversion1.2.402.v201212031633 -disabled=06target -eclipse.preferences.version=1 -override=true -suspend=false -vals/org.eclipse.jst.jsf.ui.JSFAppConfigValidator/global=FF01 -vals/org.eclipse.jst.jsp.core.JSPBatchValidator/global=FF01 -vals/org.eclipse.jst.jsp.core.JSPContentValidator/global=FF01 -vals/org.eclipse.jst.jsp.core.TLDValidator/global=FF01 -vals/org.eclipse.wst.dtd.core.dtdDTDValidator/global=FF01 -vals/org.eclipse.wst.jsdt.web.core.JsBatchValidator/global=TF02 -vf.version=3 diff --git a/spring-security-basic-auth/.settings/org.eclipse.wst.ws.service.policy.prefs b/spring-security-basic-auth/.settings/org.eclipse.wst.ws.service.policy.prefs deleted file mode 100644 index 9cfcabe16f..0000000000 --- a/spring-security-basic-auth/.settings/org.eclipse.wst.ws.service.policy.prefs +++ /dev/null @@ -1,2 +0,0 @@ -eclipse.preferences.version=1 -org.eclipse.wst.ws.service.policy.projectEnabled=false diff --git a/webjars/webjarsdemo/pom.xml b/webjars/pom.xml similarity index 100% rename from webjars/webjarsdemo/pom.xml rename to webjars/pom.xml diff --git a/webjars/webjarsdemo/src/main/java/com/baeldung/TestController.java b/webjars/src/main/java/com/baeldung/TestController.java similarity index 100% rename from webjars/webjarsdemo/src/main/java/com/baeldung/TestController.java rename to webjars/src/main/java/com/baeldung/TestController.java diff --git a/webjars/webjarsdemo/src/main/java/com/baeldung/WebjarsdemoApplication.java b/webjars/src/main/java/com/baeldung/WebjarsdemoApplication.java similarity index 100% rename from webjars/webjarsdemo/src/main/java/com/baeldung/WebjarsdemoApplication.java rename to webjars/src/main/java/com/baeldung/WebjarsdemoApplication.java diff --git a/webjars/webjarsdemo/src/main/resources/templates/index.html b/webjars/src/main/resources/templates/index.html similarity index 100% rename from webjars/webjarsdemo/src/main/resources/templates/index.html rename to webjars/src/main/resources/templates/index.html diff --git a/webjars/webjarsdemo/src/test/java/com/baeldung/WebjarsdemoApplicationTests.java b/webjars/src/test/java/com/baeldung/WebjarsdemoApplicationTests.java similarity index 100% rename from webjars/webjarsdemo/src/test/java/com/baeldung/WebjarsdemoApplicationTests.java rename to webjars/src/test/java/com/baeldung/WebjarsdemoApplicationTests.java From 000ff260175e5ba6181e942d1838de528fd72511 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sat, 23 Jul 2016 16:36:43 +0300 Subject: [PATCH 13/24] Add missing modules --- pom.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index de18c907b3..8d87555eb7 100644 --- a/pom.xml +++ b/pom.xml @@ -18,12 +18,14 @@ apache-fop core-java core-java-8 + couchbase-sdk-intro + couchbase-sdk-spring-service dependency-injection gatling gson - + gson-jackson-performance guava guava18 guava19 @@ -43,6 +45,7 @@ querydsl + rest-assured-tutorial rest-testing resteasy log4j From 94be70938689507e7f6971f61e3d6e0b649edea6 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 24 Jul 2016 10:11:46 +0300 Subject: [PATCH 14/24] Change package name --- .../controller/RestAnnotatedController.java | 4 ++-- .../com/{baledung => baeldung}/controller/RestController.java | 4 ++-- .../com/{baledung => baeldung}/controller/TestController.java | 2 +- .../main/java/com/{baledung => baeldung}/student/Student.java | 2 +- spring-controller/src/main/resources/test-mvc.xml | 2 +- .../java/com/{baledung => baeldung}/test/ControllerTest.java | 4 ++-- 6 files changed, 9 insertions(+), 9 deletions(-) rename spring-controller/src/main/java/com/{baledung => baeldung}/controller/RestAnnotatedController.java (87%) rename spring-controller/src/main/java/com/{baledung => baeldung}/controller/RestController.java (87%) rename spring-controller/src/main/java/com/{baledung => baeldung}/controller/TestController.java (94%) rename spring-controller/src/main/java/com/{baledung => baeldung}/student/Student.java (93%) rename spring-controller/src/test/java/com/{baledung => baeldung}/test/ControllerTest.java (97%) diff --git a/spring-controller/src/main/java/com/baledung/controller/RestAnnotatedController.java b/spring-controller/src/main/java/com/baeldung/controller/RestAnnotatedController.java similarity index 87% rename from spring-controller/src/main/java/com/baledung/controller/RestAnnotatedController.java rename to spring-controller/src/main/java/com/baeldung/controller/RestAnnotatedController.java index 15f9ba14d4..01c9ed4122 100644 --- a/spring-controller/src/main/java/com/baledung/controller/RestAnnotatedController.java +++ b/spring-controller/src/main/java/com/baeldung/controller/RestAnnotatedController.java @@ -1,6 +1,6 @@ -package com.baledung.controller; +package com.baeldung.controller; -import com.baledung.student.Student; +import com.baeldung.student.Student; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; diff --git a/spring-controller/src/main/java/com/baledung/controller/RestController.java b/spring-controller/src/main/java/com/baeldung/controller/RestController.java similarity index 87% rename from spring-controller/src/main/java/com/baledung/controller/RestController.java rename to spring-controller/src/main/java/com/baeldung/controller/RestController.java index e9afa88471..1281eeee57 100644 --- a/spring-controller/src/main/java/com/baledung/controller/RestController.java +++ b/spring-controller/src/main/java/com/baeldung/controller/RestController.java @@ -1,6 +1,6 @@ -package com.baledung.controller; +package com.baeldung.controller; -import com.baledung.student.Student; +import com.baeldung.student.Student; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; diff --git a/spring-controller/src/main/java/com/baledung/controller/TestController.java b/spring-controller/src/main/java/com/baeldung/controller/TestController.java similarity index 94% rename from spring-controller/src/main/java/com/baledung/controller/TestController.java rename to spring-controller/src/main/java/com/baeldung/controller/TestController.java index 8a9939b371..7397e7a2d3 100644 --- a/spring-controller/src/main/java/com/baledung/controller/TestController.java +++ b/spring-controller/src/main/java/com/baeldung/controller/TestController.java @@ -2,7 +2,7 @@ /** * @author Prashant Dutta */ -package com.baledung.controller; +package com.baeldung.controller; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; diff --git a/spring-controller/src/main/java/com/baledung/student/Student.java b/spring-controller/src/main/java/com/baeldung/student/Student.java similarity index 93% rename from spring-controller/src/main/java/com/baledung/student/Student.java rename to spring-controller/src/main/java/com/baeldung/student/Student.java index 7a5606415f..ca38360928 100644 --- a/spring-controller/src/main/java/com/baledung/student/Student.java +++ b/spring-controller/src/main/java/com/baeldung/student/Student.java @@ -1,4 +1,4 @@ -package com.baledung.student; +package com.baeldung.student; public class Student { private String name; diff --git a/spring-controller/src/main/resources/test-mvc.xml b/spring-controller/src/main/resources/test-mvc.xml index fec69e2dec..858c1b4fe5 100644 --- a/spring-controller/src/main/resources/test-mvc.xml +++ b/spring-controller/src/main/resources/test-mvc.xml @@ -10,7 +10,7 @@ http://www.springframework.org/schema/context/spring-context-4.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd"> - + diff --git a/spring-controller/src/test/java/com/baledung/test/ControllerTest.java b/spring-controller/src/test/java/com/baeldung/test/ControllerTest.java similarity index 97% rename from spring-controller/src/test/java/com/baledung/test/ControllerTest.java rename to spring-controller/src/test/java/com/baeldung/test/ControllerTest.java index 7f56d09112..8375002213 100644 --- a/spring-controller/src/test/java/com/baledung/test/ControllerTest.java +++ b/spring-controller/src/test/java/com/baeldung/test/ControllerTest.java @@ -1,4 +1,4 @@ -package com.baledung.test; +package com.baeldung.test; import org.junit.Assert; import org.junit.Before; @@ -14,7 +14,7 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.web.context.WebApplicationContext; import org.springframework.web.servlet.ModelAndView; -import com.baledung.student.Student; +import com.baeldung.student.Student; import com.fasterxml.jackson.databind.ObjectMapper; @RunWith(SpringJUnit4ClassRunner.class) From 6ee0667990531c24cae35f03a50b9f9ee23e46f8 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 24 Jul 2016 12:15:22 +0300 Subject: [PATCH 15/24] pom fix --- spring-data-neo4j/pom.xml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spring-data-neo4j/pom.xml b/spring-data-neo4j/pom.xml index a5a2e9220a..b0cf62ef2e 100644 --- a/spring-data-neo4j/pom.xml +++ b/spring-data-neo4j/pom.xml @@ -1,6 +1,6 @@ - + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + 4.0.0 com.baeldung spring-data-neo4j @@ -32,6 +32,7 @@ org.springframework.boot spring-boot-starter-test + 1.3.6.RELEASE test From 1fa1b166cae1a747d26a02e4f6364d772c98088b Mon Sep 17 00:00:00 2001 From: Alex Theedom Date: Sun, 24 Jul 2016 10:18:56 +0100 Subject: [PATCH 16/24] Change test method name to conform to required format --- .../src/test/java/com/baeldung/restassured/RestAssuredTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java index e971efe3cb..06f54aae24 100644 --- a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java +++ b/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java @@ -45,7 +45,7 @@ public class RestAssuredTest { } @Test - public void givenUrl_whenSuccessOnGetsResponse_andJsonHasRequiredKV_thenCorrect() { + public void givenUrl_whenSuccessOnGetsResponseAndJsonHasRequiredKV_thenCorrect() { get("/events?id=390").then().statusCode(200).assertThat() .body("id", equalTo("390")); From 551ee2017c5db5ebf8243a8833352a9bf8fc6d97 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 24 Jul 2016 12:53:50 +0300 Subject: [PATCH 17/24] fixes for the build --- dependency-injection/pom.xml | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/dependency-injection/pom.xml b/dependency-injection/pom.xml index 667ea87402..9e78a66ad6 100644 --- a/dependency-injection/pom.xml +++ b/dependency-injection/pom.xml @@ -1,6 +1,5 @@ - + 4.0.0 @@ -9,7 +8,7 @@ 0.0.1-SNAPSHOT war - Resource vs Inject vs Autowired + dependency-injection Accompanying the demonstration of the use of the annotations related to injection mechanisms, namely Resource, Inject, and Autowired @@ -54,6 +53,7 @@ + maven-compiler-plugin @@ -71,13 +71,29 @@ + + + org.apache.maven.plugins + maven-war-plugin + ${maven-war-plugin.version} + + false + + + + + + 2.6 + + java.net https://maven.java.net/content/repositories/releases/ + From f79715e6b21213f82d694744c0d17de47dd36c38 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 24 Jul 2016 13:01:24 +0300 Subject: [PATCH 18/24] minor cleanup --- .../.settings/org.eclipse.wst.common.project.facet.core.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml b/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml index 9ca0d1c1b7..b1c99d7726 100644 --- a/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/spring-jpa/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -3,4 +3,5 @@ + From dd99e54f3be61e5ef81d2288cfa03518149bbd62 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 24 Jul 2016 17:28:41 +0300 Subject: [PATCH 19/24] renaming a module --- {rest-assured-tutorial => rest-assured}/.gitignore | 0 {rest-assured-tutorial => rest-assured}/README.md | 0 {rest-assured-tutorial => rest-assured}/pom.xml | 0 .../src/test/java/com/baeldung/restassured/RestAssured2Test.java | 0 .../src/test/java/com/baeldung/restassured/RestAssuredTest.java | 0 .../test/java/com/baeldung/restassured/RestAssuredXML2Test.java | 0 .../test/java/com/baeldung/restassured/RestAssuredXMLTest.java | 0 .../src/test/java/com/baeldung/restassured/Util.java | 0 .../src/test/resources/employees.xml | 0 .../src/test/resources/event_0.json | 0 .../src/test/resources/log4j.properties | 0 .../src/test/resources/odds.json | 0 .../src/test/resources/teachers.xml | 0 13 files changed, 0 insertions(+), 0 deletions(-) rename {rest-assured-tutorial => rest-assured}/.gitignore (100%) rename {rest-assured-tutorial => rest-assured}/README.md (100%) rename {rest-assured-tutorial => rest-assured}/pom.xml (100%) rename {rest-assured-tutorial => rest-assured}/src/test/java/com/baeldung/restassured/RestAssured2Test.java (100%) rename {rest-assured-tutorial => rest-assured}/src/test/java/com/baeldung/restassured/RestAssuredTest.java (100%) rename {rest-assured-tutorial => rest-assured}/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java (100%) rename {rest-assured-tutorial => rest-assured}/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java (100%) rename {rest-assured-tutorial => rest-assured}/src/test/java/com/baeldung/restassured/Util.java (100%) rename {rest-assured-tutorial => rest-assured}/src/test/resources/employees.xml (100%) rename {rest-assured-tutorial => rest-assured}/src/test/resources/event_0.json (100%) rename {rest-assured-tutorial => rest-assured}/src/test/resources/log4j.properties (100%) rename {rest-assured-tutorial => rest-assured}/src/test/resources/odds.json (100%) rename {rest-assured-tutorial => rest-assured}/src/test/resources/teachers.xml (100%) diff --git a/rest-assured-tutorial/.gitignore b/rest-assured/.gitignore similarity index 100% rename from rest-assured-tutorial/.gitignore rename to rest-assured/.gitignore diff --git a/rest-assured-tutorial/README.md b/rest-assured/README.md similarity index 100% rename from rest-assured-tutorial/README.md rename to rest-assured/README.md diff --git a/rest-assured-tutorial/pom.xml b/rest-assured/pom.xml similarity index 100% rename from rest-assured-tutorial/pom.xml rename to rest-assured/pom.xml diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssured2Test.java b/rest-assured/src/test/java/com/baeldung/restassured/RestAssured2Test.java similarity index 100% rename from rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssured2Test.java rename to rest-assured/src/test/java/com/baeldung/restassured/RestAssured2Test.java diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java b/rest-assured/src/test/java/com/baeldung/restassured/RestAssuredTest.java similarity index 100% rename from rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredTest.java rename to rest-assured/src/test/java/com/baeldung/restassured/RestAssuredTest.java diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java b/rest-assured/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java similarity index 100% rename from rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java rename to rest-assured/src/test/java/com/baeldung/restassured/RestAssuredXML2Test.java diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java b/rest-assured/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java similarity index 100% rename from rest-assured-tutorial/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java rename to rest-assured/src/test/java/com/baeldung/restassured/RestAssuredXMLTest.java diff --git a/rest-assured-tutorial/src/test/java/com/baeldung/restassured/Util.java b/rest-assured/src/test/java/com/baeldung/restassured/Util.java similarity index 100% rename from rest-assured-tutorial/src/test/java/com/baeldung/restassured/Util.java rename to rest-assured/src/test/java/com/baeldung/restassured/Util.java diff --git a/rest-assured-tutorial/src/test/resources/employees.xml b/rest-assured/src/test/resources/employees.xml similarity index 100% rename from rest-assured-tutorial/src/test/resources/employees.xml rename to rest-assured/src/test/resources/employees.xml diff --git a/rest-assured-tutorial/src/test/resources/event_0.json b/rest-assured/src/test/resources/event_0.json similarity index 100% rename from rest-assured-tutorial/src/test/resources/event_0.json rename to rest-assured/src/test/resources/event_0.json diff --git a/rest-assured-tutorial/src/test/resources/log4j.properties b/rest-assured/src/test/resources/log4j.properties similarity index 100% rename from rest-assured-tutorial/src/test/resources/log4j.properties rename to rest-assured/src/test/resources/log4j.properties diff --git a/rest-assured-tutorial/src/test/resources/odds.json b/rest-assured/src/test/resources/odds.json similarity index 100% rename from rest-assured-tutorial/src/test/resources/odds.json rename to rest-assured/src/test/resources/odds.json diff --git a/rest-assured-tutorial/src/test/resources/teachers.xml b/rest-assured/src/test/resources/teachers.xml similarity index 100% rename from rest-assured-tutorial/src/test/resources/teachers.xml rename to rest-assured/src/test/resources/teachers.xml From 32f0e2ed5d417ce6fe2c664737aacd9d1e067909 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 24 Jul 2016 18:37:52 +0300 Subject: [PATCH 20/24] minor cleanup work --- apache-cxf/cxf-spring/pom.xml | 175 +++++++++--------- .../com/baeldung/cxf/spring/Baeldung.java | 1 + .../cxf/spring/ClientConfiguration.java | 2 +- .../cxf/spring/ServiceConfiguration.java | 2 +- .../com/baeldung/cxf/spring/StudentTest.java | 2 +- 5 files changed, 95 insertions(+), 87 deletions(-) diff --git a/apache-cxf/cxf-spring/pom.xml b/apache-cxf/cxf-spring/pom.xml index aa72edb739..b9dbda7c11 100644 --- a/apache-cxf/cxf-spring/pom.xml +++ b/apache-cxf/cxf-spring/pom.xml @@ -8,90 +8,7 @@ apache-cxf 0.0.1-SNAPSHOT - - 3.1.6 - 4.3.1.RELEASE - 2.19.1 - - - - - maven-war-plugin - 2.6 - - false - - - - maven-surefire-plugin - ${surefire.version} - - - StudentTest.java - - - - - - - - integration - - - - org.codehaus.cargo - cargo-maven2-plugin - 1.5.0 - - - jetty9x - embedded - - - - localhost - 8080 - - - - - - start-server - pre-integration-test - - start - - - - stop-server - post-integration-test - - stop - - - - - - maven-surefire-plugin - ${surefire.version} - - - integration-test - - test - - - - none - - - - - - - - - + org.apache.cxf @@ -119,4 +36,94 @@ 3.1.0 + + + + + maven-war-plugin + 2.6 + + false + + + + maven-surefire-plugin + ${surefire.version} + + + StudentTest.java + + + + + + + + + integration + + + + org.codehaus.cargo + cargo-maven2-plugin + 1.5.0 + + + jetty9x + embedded + + + + localhost + 8081 + + + + + + start-server + pre-integration-test + + start + + + + stop-server + post-integration-test + + stop + + + + + + + maven-surefire-plugin + ${surefire.version} + + + integration-test + + test + + + + none + + + + + + + + + + + + + 3.1.6 + 4.3.1.RELEASE + 2.19.1 + + diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/Baeldung.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/Baeldung.java index 4f880e6ada..b66e4c2fbf 100644 --- a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/Baeldung.java +++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/Baeldung.java @@ -5,5 +5,6 @@ import javax.jws.WebService; @WebService public interface Baeldung { String hello(String name); + String register(Student student); } \ No newline at end of file diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java index a2f124705b..021bcc6f66 100644 --- a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java +++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ClientConfiguration.java @@ -15,7 +15,7 @@ public class ClientConfiguration { public JaxWsProxyFactoryBean proxyFactoryBean() { JaxWsProxyFactoryBean proxyFactory = new JaxWsProxyFactoryBean(); proxyFactory.setServiceClass(Baeldung.class); - proxyFactory.setAddress("http://localhost:8080/services/baeldung"); + proxyFactory.setAddress("http://localhost:8081/services/baeldung"); return proxyFactory; } } \ No newline at end of file diff --git a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java index f1fac579ab..0bc60fb790 100644 --- a/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java +++ b/apache-cxf/cxf-spring/src/main/java/com/baeldung/cxf/spring/ServiceConfiguration.java @@ -18,7 +18,7 @@ public class ServiceConfiguration { @Bean public Endpoint endpoint() { EndpointImpl endpoint = new EndpointImpl(springBus(), new BaeldungImpl()); - endpoint.publish("http://localhost:8080/services/baeldung"); + endpoint.publish("http://localhost:8081/services/baeldung"); return endpoint; } } \ No newline at end of file diff --git a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java index 794275b4d6..7466944e04 100644 --- a/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java +++ b/apache-cxf/cxf-spring/src/test/java/com/baeldung/cxf/spring/StudentTest.java @@ -22,7 +22,7 @@ public class StudentTest { Student student2 = new Student("Eve"); String student1Response = baeldungProxy.register(student1); String student2Response = baeldungProxy.register(student2); - + assertEquals("Adam is registered student number 1", student1Response); assertEquals("Eve is registered student number 2", student2Response); } From c551e4344406967b09d7dcad00eb008fb9eb6545 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 24 Jul 2016 18:42:08 +0300 Subject: [PATCH 21/24] renaming module --- pom.xml | 2 +- rest-assured/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 8d87555eb7..074f330bcf 100644 --- a/pom.xml +++ b/pom.xml @@ -45,7 +45,7 @@ querydsl - rest-assured-tutorial + rest-assured rest-testing resteasy log4j diff --git a/rest-assured/pom.xml b/rest-assured/pom.xml index 0d5a73d075..47241b18bd 100644 --- a/rest-assured/pom.xml +++ b/rest-assured/pom.xml @@ -2,7 +2,7 @@ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 com.baeldung - rest-assured-tutorial + rest-assured 1.0 rest-assured From e4f8fc5c8ae62f7749caa1dc7bb792f69e3456a0 Mon Sep 17 00:00:00 2001 From: Grzegorz Piwowarek Date: Sun, 24 Jul 2016 21:14:08 +0300 Subject: [PATCH 22/24] Refactor ITutorialsService --- .../baeldung/mvc/velocity/service/ITutorialsService.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java b/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java index 42d6149151..24059f2662 100644 --- a/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java +++ b/spring-mvc-velocity/src/main/java/com/baeldung/mvc/velocity/service/ITutorialsService.java @@ -1,10 +1,10 @@ package com.baeldung.mvc.velocity.service; -import java.util.List; - import com.baeldung.mvc.velocity.domain.Tutorial; +import java.util.List; + public interface ITutorialsService { - public List listTutorials(); + List listTutorials(); } From d848933f207e9c602783e5fde23766e05dd5635d Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 25 Jul 2016 13:54:02 +0200 Subject: [PATCH 23/24] using StdSerializer --- .../jackson/bidirection/CustomListSerializer.java | 13 +++++++++++-- .../jackson/date/CustomDateSerializer.java | 13 +++++++++++-- .../jackson/date/CustomDateTimeSerializer.java | 14 ++++++++++++-- .../date/CustomLocalDateTimeSerializer.java | 14 ++++++++++++-- .../jackson/dtos/withEnum/TypeSerializer.java | 14 ++++++++++++-- .../jackson/serialization/ItemSerializer.java | 15 ++++++++++++--- .../serialization/ItemSerializerOnClass.java | 15 ++++++++++++--- .../serialization/MyDtoNullKeySerializer.java | 14 ++++++++++++-- 8 files changed, 94 insertions(+), 18 deletions(-) diff --git a/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListSerializer.java b/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListSerializer.java index 1d8ca011ea..75e0a4ecb7 100644 --- a/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListSerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListSerializer.java @@ -6,11 +6,20 @@ import java.util.List; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class CustomListSerializer extends JsonSerializer> { +public class CustomListSerializer extends StdSerializer> { + private static final long serialVersionUID = 3698763098000900856L; + + public CustomListSerializer() { + this(null); + } + + public CustomListSerializer(final Class> t) { + super(t); + } @Override public void serialize(final List items, final JsonGenerator generator, final SerializerProvider provider) throws IOException, JsonProcessingException { final List ids = new ArrayList(); diff --git a/jackson/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java b/jackson/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java index 8d435b7b69..d840e1940f 100644 --- a/jackson/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/date/CustomDateSerializer.java @@ -6,13 +6,22 @@ import java.util.Date; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class CustomDateSerializer extends JsonSerializer { +public class CustomDateSerializer extends StdSerializer { + private static final long serialVersionUID = -2894356342227378312L; private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); + public CustomDateSerializer() { + this(null); + } + + public CustomDateSerializer(final Class t) { + super(t); + } + @Override public void serialize(final Date value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException { gen.writeString(formatter.format(value)); diff --git a/jackson/src/test/java/com/baeldung/jackson/date/CustomDateTimeSerializer.java b/jackson/src/test/java/com/baeldung/jackson/date/CustomDateTimeSerializer.java index 88c069419b..ab4f4bbec7 100644 --- a/jackson/src/test/java/com/baeldung/jackson/date/CustomDateTimeSerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/date/CustomDateTimeSerializer.java @@ -8,10 +8,20 @@ import org.joda.time.format.DateTimeFormatter; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class CustomDateTimeSerializer extends JsonSerializer { +public class CustomDateTimeSerializer extends StdSerializer { + + private static final long serialVersionUID = -3927232057990121460L; + + public CustomDateTimeSerializer() { + this(null); + } + + public CustomDateTimeSerializer(final Class t) { + super(t); + } private static DateTimeFormatter formatter = DateTimeFormat.forPattern("yyyy-MM-dd HH:mm"); diff --git a/jackson/src/test/java/com/baeldung/jackson/date/CustomLocalDateTimeSerializer.java b/jackson/src/test/java/com/baeldung/jackson/date/CustomLocalDateTimeSerializer.java index 3f8f5e098e..dbcf42488e 100644 --- a/jackson/src/test/java/com/baeldung/jackson/date/CustomLocalDateTimeSerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/date/CustomLocalDateTimeSerializer.java @@ -6,13 +6,23 @@ import java.time.format.DateTimeFormatter; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class CustomLocalDateTimeSerializer extends JsonSerializer { +public class CustomLocalDateTimeSerializer extends StdSerializer { + + private static final long serialVersionUID = -7449444168934819290L; private static DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"); + public CustomLocalDateTimeSerializer() { + this(null); + } + + public CustomLocalDateTimeSerializer(final Class t) { + super(t); + } + @Override public void serialize(final LocalDateTime value, final JsonGenerator gen, final SerializerProvider arg2) throws IOException, JsonProcessingException { gen.writeString(formatter.format(value)); diff --git a/jackson/src/test/java/com/baeldung/jackson/dtos/withEnum/TypeSerializer.java b/jackson/src/test/java/com/baeldung/jackson/dtos/withEnum/TypeSerializer.java index c5d5d7e0a8..fc5011137c 100644 --- a/jackson/src/test/java/com/baeldung/jackson/dtos/withEnum/TypeSerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/dtos/withEnum/TypeSerializer.java @@ -4,10 +4,20 @@ import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class TypeSerializer extends JsonSerializer { +public class TypeSerializer extends StdSerializer { + + private static final long serialVersionUID = -7650668914169390772L; + + public TypeSerializer() { + this(null); + } + + public TypeSerializer(final Class t) { + super(t); + } @Override public void serialize(final TypeEnumWithCustomSerializer value, final JsonGenerator generator, final SerializerProvider provider) throws IOException, JsonProcessingException { diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java b/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java index cb93f9cb03..b5624c566a 100644 --- a/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializer.java @@ -3,13 +3,22 @@ package com.baeldung.jackson.serialization; import java.io.IOException; import com.baeldung.jackson.dtos.Item; - import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class ItemSerializer extends JsonSerializer { +public class ItemSerializer extends StdSerializer { + + private static final long serialVersionUID = 6739170890621978901L; + + public ItemSerializer() { + this(null); + } + + public ItemSerializer(final Class t) { + super(t); + } @Override public final void serialize(final Item value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java b/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java index 79b450d7f1..1fdf44e17c 100644 --- a/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java +++ b/jackson/src/test/java/com/baeldung/jackson/serialization/ItemSerializerOnClass.java @@ -3,13 +3,22 @@ package com.baeldung.jackson.serialization; import java.io.IOException; import com.baeldung.jackson.dtos.ItemWithSerializer; - import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class ItemSerializerOnClass extends JsonSerializer { +public class ItemSerializerOnClass extends StdSerializer { + + private static final long serialVersionUID = -1760959597313610409L; + + public ItemSerializerOnClass() { + this(null); + } + + public ItemSerializerOnClass(final Class t) { + super(t); + } @Override public final void serialize(final ItemWithSerializer value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { diff --git a/jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java b/jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java index e915378498..d0b2d7f5e9 100644 --- a/jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/serialization/MyDtoNullKeySerializer.java @@ -4,10 +4,20 @@ import java.io.IOException; import com.fasterxml.jackson.core.JsonGenerator; import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonSerializer; import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; -public class MyDtoNullKeySerializer extends JsonSerializer { +public class MyDtoNullKeySerializer extends StdSerializer { + + private static final long serialVersionUID = -4478531309177369056L; + + public MyDtoNullKeySerializer() { + this(null); + } + + public MyDtoNullKeySerializer(final Class t) { + super(t); + } @Override public void serialize(final Object value, final JsonGenerator jgen, final SerializerProvider provider) throws IOException, JsonProcessingException { From cc8632120ca24d8cc837b21b5dccafa5009dbab9 Mon Sep 17 00:00:00 2001 From: DOHA Date: Mon, 25 Jul 2016 13:54:18 +0200 Subject: [PATCH 24/24] using StdDeserializer --- .../bidirection/CustomListDeserializer.java | 14 ++++++++++++-- .../jackson/date/CustomDateDeserializer.java | 13 +++++++++++-- .../deserialization/ItemDeserializer.java | 17 +++++++++++++---- .../ItemDeserializerOnClass.java | 15 ++++++++++++--- .../try1/RestLoaderRequestDeserializer.java | 13 +++++++++++-- 5 files changed, 59 insertions(+), 13 deletions(-) diff --git a/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListDeserializer.java b/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListDeserializer.java index 5f1f1edf2b..c00316e365 100644 --- a/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListDeserializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/bidirection/CustomListDeserializer.java @@ -7,9 +7,19 @@ import java.util.List; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -public class CustomListDeserializer extends JsonDeserializer> { +public class CustomListDeserializer extends StdDeserializer> { + + private static final long serialVersionUID = 1095767961632979804L; + + public CustomListDeserializer() { + this(null); + } + + public CustomListDeserializer(final Class vc) { + super(vc); + } @Override public List deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException { diff --git a/jackson/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java b/jackson/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java index a63190c8f5..90c7d9fbac 100644 --- a/jackson/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/date/CustomDateDeserializer.java @@ -8,12 +8,21 @@ import java.util.Date; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -public class CustomDateDeserializer extends JsonDeserializer { +public class CustomDateDeserializer extends StdDeserializer { + private static final long serialVersionUID = -5451717385630622729L; private SimpleDateFormat formatter = new SimpleDateFormat("dd-MM-yyyy hh:mm:ss"); + public CustomDateDeserializer() { + this(null); + } + + public CustomDateDeserializer(final Class vc) { + super(vc); + } + @Override public Date deserialize(final JsonParser jsonparser, final DeserializationContext context) throws IOException, JsonProcessingException { final String date = jsonparser.getText(); diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializer.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializer.java index 3be6685103..e9c89b8c78 100644 --- a/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializer.java @@ -2,17 +2,26 @@ package com.baeldung.jackson.deserialization; import java.io.IOException; -import com.baeldung.jackson.dtos.User; import com.baeldung.jackson.dtos.Item; - +import com.baeldung.jackson.dtos.User; import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.fasterxml.jackson.databind.node.IntNode; -public class ItemDeserializer extends JsonDeserializer { +public class ItemDeserializer extends StdDeserializer { + + private static final long serialVersionUID = 1883547683050039861L; + + public ItemDeserializer() { + this(null); + } + + public ItemDeserializer(final Class vc) { + super(vc); + } /** * {"id":1,"itemNr":"theItem","owner":2} diff --git a/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java b/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java index 169a5c1c50..2036780e99 100644 --- a/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java +++ b/jackson/src/test/java/com/baeldung/jackson/deserialization/ItemDeserializerOnClass.java @@ -4,15 +4,24 @@ import java.io.IOException; import com.baeldung.jackson.dtos.ItemWithSerializer; import com.baeldung.jackson.dtos.User; - import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; import com.fasterxml.jackson.databind.node.IntNode; -public class ItemDeserializerOnClass extends JsonDeserializer { +public class ItemDeserializerOnClass extends StdDeserializer { + + private static final long serialVersionUID = 5579141241817332594L; + + public ItemDeserializerOnClass() { + this(null); + } + + public ItemDeserializerOnClass(final Class vc) { + super(vc); + } /** * {"id":1,"itemNr":"theItem","owner":2} diff --git a/jackson/src/test/java/com/baeldung/jackson/try1/RestLoaderRequestDeserializer.java b/jackson/src/test/java/com/baeldung/jackson/try1/RestLoaderRequestDeserializer.java index 849607586d..529c05ddcc 100644 --- a/jackson/src/test/java/com/baeldung/jackson/try1/RestLoaderRequestDeserializer.java +++ b/jackson/src/test/java/com/baeldung/jackson/try1/RestLoaderRequestDeserializer.java @@ -6,10 +6,19 @@ import com.fasterxml.jackson.core.JsonParser; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.core.ObjectCodec; import com.fasterxml.jackson.databind.DeserializationContext; -import com.fasterxml.jackson.databind.JsonDeserializer; import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; -public class RestLoaderRequestDeserializer extends JsonDeserializer> { +public class RestLoaderRequestDeserializer extends StdDeserializer> { + private static final long serialVersionUID = -4245207329377196889L; + + public RestLoaderRequestDeserializer() { + this(null); + } + + public RestLoaderRequestDeserializer(final Class vc) { + super(vc); + } @Override public RestLoaderRequest deserialize(final JsonParser jp, final DeserializationContext ctxt) throws IOException, JsonProcessingException {