formatting work
This commit is contained in:
parent
eb7650eead
commit
856be0a08a
@ -29,5 +29,4 @@ public class SpringExtension extends AbstractExtensionId<SpringExtension.SpringE
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -27,9 +27,7 @@ public class SpringAkkaTest extends AbstractJUnit4SpringContextTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCallingGreetingActor_thenActorGreetsTheCaller() throws Exception {
|
public void whenCallingGreetingActor_thenActorGreetsTheCaller() throws Exception {
|
||||||
ActorRef greeter = system.actorOf(
|
ActorRef greeter = system.actorOf(SPRING_EXTENSION_PROVIDER.get(system).props("greetingActor"), "greeter");
|
||||||
SPRING_EXTENSION_PROVIDER.get(system)
|
|
||||||
.props("greetingActor"), "greeter");
|
|
||||||
|
|
||||||
FiniteDuration duration = FiniteDuration.create(1, TimeUnit.SECONDS);
|
FiniteDuration duration = FiniteDuration.create(1, TimeUnit.SECONDS);
|
||||||
Timeout timeout = Timeout.durationToTimeout(duration);
|
Timeout timeout = Timeout.durationToTimeout(duration);
|
||||||
|
@ -11,7 +11,6 @@ public class PropertiesWithPlaceHolderConfigurer {
|
|||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public PropertyPlaceholderConfigurer propertyConfigurer() {
|
public PropertyPlaceholderConfigurer propertyConfigurer() {
|
||||||
final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
|
final PropertyPlaceholderConfigurer props = new PropertyPlaceholderConfigurer();
|
||||||
|
@ -11,7 +11,6 @@ public class Foo {
|
|||||||
|
|
||||||
private static final AtomicInteger instanceCount = new AtomicInteger(0);
|
private static final AtomicInteger instanceCount = new AtomicInteger(0);
|
||||||
|
|
||||||
|
|
||||||
private final int instanceNum;
|
private final int instanceNum;
|
||||||
|
|
||||||
public Foo() {
|
public Foo() {
|
||||||
|
@ -18,7 +18,6 @@ import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
|||||||
import org.springframework.web.context.WebApplicationContext;
|
import org.springframework.web.context.WebApplicationContext;
|
||||||
import org.springframework.web.servlet.ModelAndView;
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
|
|
||||||
|
|
||||||
@RunWith(SpringJUnit4ClassRunner.class)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@WebAppConfiguration
|
@WebAppConfiguration
|
||||||
@ContextConfiguration(classes = { WebConfig.class }, loader = AnnotationConfigWebContextLoader.class)
|
@ContextConfiguration(classes = { WebConfig.class }, loader = AnnotationConfigWebContextLoader.class)
|
||||||
@ -43,9 +42,7 @@ public class ControllerAnnotationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testTestController() throws Exception {
|
public void testTestController() throws Exception {
|
||||||
|
|
||||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/"))
|
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/")).andReturn().getModelAndView();
|
||||||
.andReturn()
|
|
||||||
.getModelAndView();
|
|
||||||
|
|
||||||
// validate modal data
|
// validate modal data
|
||||||
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
|
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
|
||||||
@ -57,9 +54,7 @@ public class ControllerAnnotationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRestController() throws Exception {
|
public void testRestController() throws Exception {
|
||||||
|
|
||||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1))
|
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||||
.andReturn().getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
ObjectMapper reader = new ObjectMapper();
|
ObjectMapper reader = new ObjectMapper();
|
||||||
|
|
||||||
@ -72,9 +67,7 @@ public class ControllerAnnotationTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRestAnnotatedController() throws Exception {
|
public void testRestAnnotatedController() throws Exception {
|
||||||
|
|
||||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1))
|
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||||
.andReturn().getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
ObjectMapper reader = new ObjectMapper();
|
ObjectMapper reader = new ObjectMapper();
|
||||||
|
|
||||||
|
@ -41,9 +41,7 @@ public class ControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testTestController() throws Exception {
|
public void testTestController() throws Exception {
|
||||||
|
|
||||||
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/"))
|
ModelAndView mv = this.mockMvc.perform(MockMvcRequestBuilders.get("/test/")).andReturn().getModelAndView();
|
||||||
.andReturn()
|
|
||||||
.getModelAndView();
|
|
||||||
|
|
||||||
// validate modal data
|
// validate modal data
|
||||||
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
|
Assert.assertSame(mv.getModelMap().get("data").toString(), "Welcome home man");
|
||||||
@ -55,9 +53,7 @@ public class ControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRestController() throws Exception {
|
public void testRestController() throws Exception {
|
||||||
|
|
||||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1))
|
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||||
.andReturn().getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
ObjectMapper reader = new ObjectMapper();
|
ObjectMapper reader = new ObjectMapper();
|
||||||
|
|
||||||
@ -70,9 +66,7 @@ public class ControllerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testRestAnnotatedController() throws Exception {
|
public void testRestAnnotatedController() throws Exception {
|
||||||
|
|
||||||
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1))
|
String responseBody = this.mockMvc.perform(MockMvcRequestBuilders.get("/annotated/student/{studentId}", 1)).andReturn().getResponse().getContentAsString();
|
||||||
.andReturn().getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
ObjectMapper reader = new ObjectMapper();
|
ObjectMapper reader = new ObjectMapper();
|
||||||
|
|
||||||
|
@ -26,18 +26,12 @@ public class AttributeAnnotationTest extends AbstractJUnit4SpringContextTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenInterceptorAddsRequestAndSessionParams_thenParamsInjectedWithAttributesAnnotations() throws Exception {
|
public void whenInterceptorAddsRequestAndSessionParams_thenParamsInjectedWithAttributesAnnotations() throws Exception {
|
||||||
String result = this.mockMvc.perform(get("/test")
|
String result = this.mockMvc.perform(get("/test").accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.accept(MediaType.ALL))
|
|
||||||
.andExpect(status().isOk())
|
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
Assert.assertEquals("login = john, query = invoices", result);
|
Assert.assertEquals("login = john, query = invoices", result);
|
||||||
}
|
}
|
||||||
|
@ -29,15 +29,12 @@ public class ComposedMappingTest extends AbstractJUnit4SpringContextTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenRequestingMethodWithGetMapping_thenReceiving200Answer() throws Exception {
|
public void whenRequestingMethodWithGetMapping_thenReceiving200Answer() throws Exception {
|
||||||
this.mockMvc.perform(get("/appointments")
|
this.mockMvc.perform(get("/appointments").accept(MediaType.ALL)).andExpect(status().isOk());
|
||||||
.accept(MediaType.ALL))
|
|
||||||
.andExpect(status().isOk());
|
|
||||||
verify(appointmentService);
|
verify(appointmentService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package org.baeldung.spring43.defaultmethods;
|
package org.baeldung.spring43.defaultmethods;
|
||||||
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
|
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
@ -28,27 +28,16 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
|
|||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac)
|
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenDifferentRequests_thenDifferentInstancesOfRequestScopedBeans() throws Exception {
|
public void whenDifferentRequests_thenDifferentInstancesOfRequestScopedBeans() throws Exception {
|
||||||
MockHttpSession session = new MockHttpSession();
|
MockHttpSession session = new MockHttpSession();
|
||||||
|
|
||||||
String requestScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/request")
|
String requestScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/request").session(session).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.session(session)
|
|
||||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
String requestScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/request")
|
String requestScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/request").session(session).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.session(session)
|
|
||||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
assertNotEquals(requestScopedServiceInstanceNumber1, requestScopedServiceInstanceNumber2);
|
assertNotEquals(requestScopedServiceInstanceNumber1, requestScopedServiceInstanceNumber2);
|
||||||
}
|
}
|
||||||
@ -59,24 +48,9 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
|
|||||||
MockHttpSession session1 = new MockHttpSession();
|
MockHttpSession session1 = new MockHttpSession();
|
||||||
MockHttpSession session2 = new MockHttpSession();
|
MockHttpSession session2 = new MockHttpSession();
|
||||||
|
|
||||||
String sessionScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/session")
|
String sessionScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/session").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.session(session1)
|
String sessionScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/session").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
String sessionScopedServiceInstanceNumber3 = this.mockMvc.perform(get("/appointments/session").session(session2).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
String sessionScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/session")
|
|
||||||
.session(session1)
|
|
||||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
String sessionScopedServiceInstanceNumber3 = this.mockMvc.perform(get("/appointments/session")
|
|
||||||
.session(session2)
|
|
||||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
assertEquals(sessionScopedServiceInstanceNumber1, sessionScopedServiceInstanceNumber2);
|
assertEquals(sessionScopedServiceInstanceNumber1, sessionScopedServiceInstanceNumber2);
|
||||||
|
|
||||||
@ -90,18 +64,8 @@ public class ScopeAnnotationsTest extends AbstractJUnit4SpringContextTests {
|
|||||||
MockHttpSession session1 = new MockHttpSession();
|
MockHttpSession session1 = new MockHttpSession();
|
||||||
MockHttpSession session2 = new MockHttpSession();
|
MockHttpSession session2 = new MockHttpSession();
|
||||||
|
|
||||||
String applicationScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/application")
|
String applicationScopedServiceInstanceNumber1 = this.mockMvc.perform(get("/appointments/application").session(session1).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.session(session1)
|
String applicationScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/application").session(session2).accept(MediaType.ALL)).andExpect(status().isOk()).andReturn().getResponse().getContentAsString();
|
||||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
String applicationScopedServiceInstanceNumber2 = this.mockMvc.perform(get("/appointments/application")
|
|
||||||
.session(session2)
|
|
||||||
.accept(MediaType.ALL)).andExpect(status().isOk())
|
|
||||||
.andReturn()
|
|
||||||
.getResponse()
|
|
||||||
.getContentAsString();
|
|
||||||
|
|
||||||
assertEquals(applicationScopedServiceInstanceNumber1, applicationScopedServiceInstanceNumber2);
|
assertEquals(applicationScopedServiceInstanceNumber1, applicationScopedServiceInstanceNumber2);
|
||||||
|
|
||||||
|
@ -21,6 +21,3 @@ public class CommitIdApplication {
|
|||||||
return c;
|
return c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -32,13 +32,10 @@ public class CommitIdTest {
|
|||||||
LOG.info(commitMessage);
|
LOG.info(commitMessage);
|
||||||
LOG.info(branch);
|
LOG.info(branch);
|
||||||
|
|
||||||
assertThat(commitMessage)
|
assertThat(commitMessage).isNotEqualTo("UNKNOWN");
|
||||||
.isNotEqualTo("UNKNOWN");
|
|
||||||
|
|
||||||
assertThat(branch)
|
assertThat(branch).isNotEqualTo("UNKNOWN");
|
||||||
.isNotEqualTo("UNKNOWN");
|
|
||||||
|
|
||||||
assertThat(commitId)
|
assertThat(commitId).isNotEqualTo("UNKNOWN");
|
||||||
.isNotEqualTo("UNKNOWN");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -31,22 +31,15 @@ public class SpringBootApplicationTest {
|
|||||||
private WebApplicationContext webApplicationContext;
|
private WebApplicationContext webApplicationContext;
|
||||||
private MockMvc mockMvc;
|
private MockMvc mockMvc;
|
||||||
|
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setupMockMvc() {
|
public void setupMockMvc() {
|
||||||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext)
|
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect() throws Exception {
|
public void givenRequestHasBeenMade_whenMeetsAllOfGivenConditions_thenCorrect() throws Exception {
|
||||||
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(),
|
MediaType contentType = new MediaType(MediaType.APPLICATION_JSON.getType(), MediaType.APPLICATION_JSON.getSubtype(), Charset.forName("utf8"));
|
||||||
MediaType.APPLICATION_JSON.getSubtype(),
|
|
||||||
Charset.forName("utf8"));
|
|
||||||
|
|
||||||
mockMvc.perform(MockMvcRequestBuilders.get("/entity/all")).
|
mockMvc.perform(MockMvcRequestBuilders.get("/entity/all")).andExpect(MockMvcResultMatchers.status().isOk()).andExpect(MockMvcResultMatchers.content().contentType(contentType)).andExpect(jsonPath("$", hasSize(4)));
|
||||||
andExpect(MockMvcResultMatchers.status().isOk()).
|
|
||||||
andExpect(MockMvcResultMatchers.content().contentType(contentType)).
|
|
||||||
andExpect(jsonPath("$", hasSize(4)));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -69,7 +69,6 @@ public class SpringBootMailTest {
|
|||||||
return wiserMessage.getMimeMessage().getSubject();
|
return wiserMessage.getMimeMessage().getSubject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private SimpleMailMessage composeEmailMessage() {
|
private SimpleMailMessage composeEmailMessage() {
|
||||||
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
SimpleMailMessage mailMessage = new SimpleMailMessage();
|
||||||
mailMessage.setTo(userTo);
|
mailMessage.setTo(userTo);
|
||||||
|
@ -30,8 +30,7 @@ public class DetailsServiceClientTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() throws Exception {
|
public void setUp() throws Exception {
|
||||||
String detailsString = objectMapper.writeValueAsString(new Details("John Smith", "john"));
|
String detailsString = objectMapper.writeValueAsString(new Details("John Smith", "john"));
|
||||||
this.server.expect(requestTo("/john/details"))
|
this.server.expect(requestTo("/john/details")).andRespond(withSuccess(detailsString, MediaType.APPLICATION_JSON));
|
||||||
.andRespond(withSuccess(detailsString, MediaType.APPLICATION_JSON));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -23,18 +23,23 @@ public class Campus {
|
|||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Point getLocation() {
|
public Point getLocation() {
|
||||||
return location;
|
return location;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLocation(Point location) {
|
public void setLocation(Point location) {
|
||||||
this.location = location;
|
this.location = location;
|
||||||
}
|
}
|
||||||
@ -56,14 +61,17 @@ public class Campus {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if((obj == null) || (obj.getClass() != this.getClass())) return false;
|
if ((obj == null) || (obj.getClass() != this.getClass()))
|
||||||
if(obj == this) return true;
|
return false;
|
||||||
|
if (obj == this)
|
||||||
|
return true;
|
||||||
Campus other = (Campus) obj;
|
Campus other = (Campus) obj;
|
||||||
return this.hashCode() == other.hashCode();
|
return this.hashCode() == other.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private Campus() {}
|
private Campus() {
|
||||||
|
}
|
||||||
|
|
||||||
public Campus(Builder b) {
|
public Campus(Builder b) {
|
||||||
this.id = b.id;
|
this.id = b.id;
|
||||||
|
@ -34,30 +34,39 @@ public class Person {
|
|||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
return firstName;
|
return firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
public void setFirstName(String firstName) {
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastName() {
|
public String getLastName() {
|
||||||
return lastName;
|
return lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
public void setLastName(String lastName) {
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getCreated() {
|
public DateTime getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreated(DateTime created) {
|
public void setCreated(DateTime created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getUpdated() {
|
public DateTime getUpdated() {
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdated(DateTime updated) {
|
public void setUpdated(DateTime updated) {
|
||||||
this.updated = updated;
|
this.updated = updated;
|
||||||
}
|
}
|
||||||
@ -79,8 +88,10 @@ public class Person {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if((obj == null) || (obj.getClass() != this.getClass())) return false;
|
if ((obj == null) || (obj.getClass() != this.getClass()))
|
||||||
if(obj == this) return true;
|
return false;
|
||||||
|
if (obj == this)
|
||||||
|
return true;
|
||||||
Person other = (Person) obj;
|
Person other = (Person) obj;
|
||||||
return this.hashCode() == other.hashCode();
|
return this.hashCode() == other.hashCode();
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,8 @@ public class Student {
|
|||||||
@Version
|
@Version
|
||||||
private long version;
|
private long version;
|
||||||
|
|
||||||
public Student() {}
|
public Student() {
|
||||||
|
}
|
||||||
|
|
||||||
public Student(String id, String firstName, String lastName, DateTime dateOfBirth) {
|
public Student(String id, String firstName, String lastName, DateTime dateOfBirth) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
@ -51,36 +52,47 @@ public class Student {
|
|||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
return firstName;
|
return firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setFirstName(String firstName) {
|
public void setFirstName(String firstName) {
|
||||||
this.firstName = firstName;
|
this.firstName = firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLastName() {
|
public String getLastName() {
|
||||||
return lastName;
|
return lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setLastName(String lastName) {
|
public void setLastName(String lastName) {
|
||||||
this.lastName = lastName;
|
this.lastName = lastName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getDateOfBirth() {
|
public DateTime getDateOfBirth() {
|
||||||
return dateOfBirth;
|
return dateOfBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDateOfBirth(DateTime dateOfBirth) {
|
public void setDateOfBirth(DateTime dateOfBirth) {
|
||||||
this.dateOfBirth = dateOfBirth;
|
this.dateOfBirth = dateOfBirth;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getCreated() {
|
public DateTime getCreated() {
|
||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCreated(DateTime created) {
|
public void setCreated(DateTime created) {
|
||||||
this.created = created;
|
this.created = created;
|
||||||
}
|
}
|
||||||
|
|
||||||
public DateTime getUpdated() {
|
public DateTime getUpdated() {
|
||||||
return updated;
|
return updated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUpdated(DateTime updated) {
|
public void setUpdated(DateTime updated) {
|
||||||
this.updated = updated;
|
this.updated = updated;
|
||||||
}
|
}
|
||||||
@ -105,8 +117,10 @@ public class Student {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if((obj == null) || (obj.getClass() != this.getClass())) return false;
|
if ((obj == null) || (obj.getClass() != this.getClass()))
|
||||||
if(obj == this) return true;
|
return false;
|
||||||
|
if (obj == this)
|
||||||
|
return true;
|
||||||
Student other = (Student) obj;
|
Student other = (Student) obj;
|
||||||
return this.hashCode() == other.hashCode();
|
return this.hashCode() == other.hashCode();
|
||||||
}
|
}
|
||||||
|
@ -17,9 +17,6 @@ public class CustomStudentRepositoryImpl implements CustomStudentRepository {
|
|||||||
private CouchbaseTemplate template;
|
private CouchbaseTemplate template;
|
||||||
|
|
||||||
public List<Student> findByFirstNameStartsWith(String s) {
|
public List<Student> findByFirstNameStartsWith(String s) {
|
||||||
return template.findByView(ViewQuery.from(DESIGN_DOC, "byFirstName")
|
return template.findByView(ViewQuery.from(DESIGN_DOC, "byFirstName").startKey(s).stale(Stale.FALSE), Student.class);
|
||||||
.startKey(s)
|
|
||||||
.stale(Stale.FALSE),
|
|
||||||
Student.class);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,6 @@ import org.springframework.data.repository.CrudRepository;
|
|||||||
|
|
||||||
public interface PersonRepository extends CrudRepository<Person, String> {
|
public interface PersonRepository extends CrudRepository<Person, String> {
|
||||||
List<Person> findByFirstName(String firstName);
|
List<Person> findByFirstName(String firstName);
|
||||||
|
|
||||||
List<Person> findByLastName(String lastName);
|
List<Person> findByLastName(String lastName);
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,6 @@ import org.springframework.data.repository.CrudRepository;
|
|||||||
|
|
||||||
public interface StudentRepository extends CrudRepository<Student, String>, CustomStudentRepository {
|
public interface StudentRepository extends CrudRepository<Student, String>, CustomStudentRepository {
|
||||||
List<Student> findByFirstName(String firstName);
|
List<Student> findByFirstName(String firstName);
|
||||||
|
|
||||||
List<Student> findByLastName(String lastName);
|
List<Student> findByLastName(String lastName);
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|||||||
public class PersonRepositoryService implements PersonService {
|
public class PersonRepositoryService implements PersonService {
|
||||||
|
|
||||||
private PersonRepository repo;
|
private PersonRepository repo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setPersonRepository(PersonRepository repo) {
|
public void setPersonRepository(PersonRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -18,6 +18,7 @@ public class PersonTemplateService implements PersonService {
|
|||||||
private static final String DESIGN_DOC = "person";
|
private static final String DESIGN_DOC = "person";
|
||||||
|
|
||||||
private CouchbaseTemplate template;
|
private CouchbaseTemplate template;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setCouchbaseTemplate(CouchbaseTemplate template) {
|
public void setCouchbaseTemplate(CouchbaseTemplate template) {
|
||||||
this.template = template;
|
this.template = template;
|
||||||
|
@ -16,6 +16,7 @@ import org.springframework.stereotype.Service;
|
|||||||
public class StudentRepositoryService implements StudentService {
|
public class StudentRepositoryService implements StudentService {
|
||||||
|
|
||||||
private StudentRepository repo;
|
private StudentRepository repo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setStudentRepository(StudentRepository repo) {
|
public void setStudentRepository(StudentRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -18,6 +18,7 @@ public class StudentTemplateService implements StudentService {
|
|||||||
private static final String DESIGN_DOC = "student";
|
private static final String DESIGN_DOC = "student";
|
||||||
|
|
||||||
private CouchbaseTemplate template;
|
private CouchbaseTemplate template;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setCouchbaseTemplate(CouchbaseTemplate template) {
|
public void setCouchbaseTemplate(CouchbaseTemplate template) {
|
||||||
this.template = template;
|
this.template = template;
|
||||||
|
@ -7,5 +7,6 @@ import org.springframework.data.repository.CrudRepository;
|
|||||||
|
|
||||||
public interface PersonRepository extends CrudRepository<Person, String> {
|
public interface PersonRepository extends CrudRepository<Person, String> {
|
||||||
List<Person> findByFirstName(String firstName);
|
List<Person> findByFirstName(String firstName);
|
||||||
|
|
||||||
List<Person> findByLastName(String lastName);
|
List<Person> findByLastName(String lastName);
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,6 @@ import org.springframework.data.repository.CrudRepository;
|
|||||||
|
|
||||||
public interface StudentRepository extends CrudRepository<Student, String> {
|
public interface StudentRepository extends CrudRepository<Student, String> {
|
||||||
List<Student> findByFirstName(String firstName);
|
List<Student> findByFirstName(String firstName);
|
||||||
|
|
||||||
List<Student> findByLastName(String lastName);
|
List<Student> findByLastName(String lastName);
|
||||||
}
|
}
|
||||||
|
@ -15,6 +15,7 @@ import org.springframework.stereotype.Service;
|
|||||||
public class CampusServiceImpl implements CampusService {
|
public class CampusServiceImpl implements CampusService {
|
||||||
|
|
||||||
private CampusRepository repo;
|
private CampusRepository repo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setCampusRepository(CampusRepository repo) {
|
public void setCampusRepository(CampusRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|||||||
public class PersonServiceImpl implements PersonService {
|
public class PersonServiceImpl implements PersonService {
|
||||||
|
|
||||||
private PersonRepository repo;
|
private PersonRepository repo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setPersonRepository(PersonRepository repo) {
|
public void setPersonRepository(PersonRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -14,6 +14,7 @@ import org.springframework.stereotype.Service;
|
|||||||
public class StudentServiceImpl implements StudentService {
|
public class StudentServiceImpl implements StudentService {
|
||||||
|
|
||||||
private StudentRepository repo;
|
private StudentRepository repo;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public void setStudentRepository(StudentRepository repo) {
|
public void setStudentRepository(StudentRepository repo) {
|
||||||
this.repo = repo;
|
this.repo = repo;
|
||||||
|
@ -30,24 +30,14 @@ public abstract class StudentServiceTest extends IntegrationTest {
|
|||||||
static final String joeCollegeId = "student:" + joe + ":" + college;
|
static final String joeCollegeId = "student:" + joe + ":" + college;
|
||||||
static final DateTime joeCollegeDob = DateTime.now().minusYears(21);
|
static final DateTime joeCollegeDob = DateTime.now().minusYears(21);
|
||||||
static final Student joeCollege = new Student(joeCollegeId, joe, college, joeCollegeDob);
|
static final Student joeCollege = new Student(joeCollegeId, joe, college, joeCollegeDob);
|
||||||
static final JsonObject jsonJoeCollege = JsonObject.empty()
|
static final JsonObject jsonJoeCollege = JsonObject.empty().put(typeField, Student.class.getName()).put("firstName", joe).put("lastName", college).put("created", DateTime.now().getMillis()).put("version", 1);
|
||||||
.put(typeField, Student.class.getName())
|
|
||||||
.put("firstName", joe)
|
|
||||||
.put("lastName", college)
|
|
||||||
.put("created", DateTime.now().getMillis())
|
|
||||||
.put("version", 1);
|
|
||||||
|
|
||||||
static final String judy = "Judy";
|
static final String judy = "Judy";
|
||||||
static final String jetson = "Jetson";
|
static final String jetson = "Jetson";
|
||||||
static final String judyJetsonId = "student:" + judy + ":" + jetson;
|
static final String judyJetsonId = "student:" + judy + ":" + jetson;
|
||||||
static final DateTime judyJetsonDob = DateTime.now().minusYears(19).minusMonths(5).minusDays(3);
|
static final DateTime judyJetsonDob = DateTime.now().minusYears(19).minusMonths(5).minusDays(3);
|
||||||
static final Student judyJetson = new Student(judyJetsonId, judy, jetson, judyJetsonDob);
|
static final Student judyJetson = new Student(judyJetsonId, judy, jetson, judyJetsonDob);
|
||||||
static final JsonObject jsonJudyJetson = JsonObject.empty()
|
static final JsonObject jsonJudyJetson = JsonObject.empty().put(typeField, Student.class.getName()).put("firstName", judy).put("lastName", jetson).put("created", DateTime.now().getMillis()).put("version", 1);
|
||||||
.put(typeField, Student.class.getName())
|
|
||||||
.put("firstName", judy)
|
|
||||||
.put("lastName", jetson)
|
|
||||||
.put("created", DateTime.now().getMillis())
|
|
||||||
.put("version", 1);
|
|
||||||
|
|
||||||
StudentService studentService;
|
StudentService studentService;
|
||||||
|
|
||||||
|
@ -46,11 +46,7 @@ public class MultiBucketCouchbaseConfig extends AbstractCouchbaseConfiguration {
|
|||||||
|
|
||||||
@Bean(name = "campusTemplate")
|
@Bean(name = "campusTemplate")
|
||||||
public CouchbaseTemplate campusTemplate() throws Exception {
|
public CouchbaseTemplate campusTemplate() throws Exception {
|
||||||
CouchbaseTemplate template = new CouchbaseTemplate(
|
CouchbaseTemplate template = new CouchbaseTemplate(couchbaseClusterInfo(), campusBucket(), mappingCouchbaseConverter(), translationService());
|
||||||
couchbaseClusterInfo(),
|
|
||||||
campusBucket(),
|
|
||||||
mappingCouchbaseConverter(),
|
|
||||||
translationService());
|
|
||||||
template.setDefaultConsistency(getDefaultConsistency());
|
template.setDefaultConsistency(getDefaultConsistency());
|
||||||
return template;
|
return template;
|
||||||
}
|
}
|
||||||
|
@ -26,53 +26,21 @@ public class CampusServiceImplTest extends MultiBucketIntegationTest {
|
|||||||
@Autowired
|
@Autowired
|
||||||
private CampusRepository campusRepo;
|
private CampusRepository campusRepo;
|
||||||
|
|
||||||
private final Campus Brown = Campus.Builder.newInstance()
|
private final Campus Brown = Campus.Builder.newInstance().id("campus:Brown").name("Brown").location(new Point(71.4025, 51.8268)).build();
|
||||||
.id("campus:Brown")
|
|
||||||
.name("Brown")
|
|
||||||
.location(new Point(71.4025, 51.8268))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Campus Cornell = Campus.Builder.newInstance()
|
private final Campus Cornell = Campus.Builder.newInstance().id("campus:Cornell").name("Cornell").location(new Point(76.4833, 42.4459)).build();
|
||||||
.id("campus:Cornell")
|
|
||||||
.name("Cornell")
|
|
||||||
.location(new Point(76.4833, 42.4459))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Campus Columbia = Campus.Builder.newInstance()
|
private final Campus Columbia = Campus.Builder.newInstance().id("campus:Columbia").name("Columbia").location(new Point(73.9626, 40.8075)).build();
|
||||||
.id("campus:Columbia")
|
|
||||||
.name("Columbia")
|
|
||||||
.location(new Point(73.9626, 40.8075))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Campus Dartmouth = Campus.Builder.newInstance()
|
private final Campus Dartmouth = Campus.Builder.newInstance().id("campus:Dartmouth").name("Dartmouth").location(new Point(72.2887, 43.7044)).build();
|
||||||
.id("campus:Dartmouth")
|
|
||||||
.name("Dartmouth")
|
|
||||||
.location(new Point(72.2887, 43.7044))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Campus Harvard = Campus.Builder.newInstance()
|
private final Campus Harvard = Campus.Builder.newInstance().id("campus:Harvard").name("Harvard").location(new Point(71.1167, 42.3770)).build();
|
||||||
.id("campus:Harvard")
|
|
||||||
.name("Harvard")
|
|
||||||
.location(new Point(71.1167, 42.3770))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Campus Penn = Campus.Builder.newInstance()
|
private final Campus Penn = Campus.Builder.newInstance().id("campus:Penn").name("Penn").location(new Point(75.1932, 39.9522)).build();
|
||||||
.id("campus:Penn")
|
|
||||||
.name("Penn")
|
|
||||||
.location(new Point(75.1932, 39.9522))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Campus Princeton = Campus.Builder.newInstance()
|
private final Campus Princeton = Campus.Builder.newInstance().id("campus:Princeton").name("Princeton").location(new Point(74.6514, 40.3340)).build();
|
||||||
.id("campus:Princeton")
|
|
||||||
.name("Princeton")
|
|
||||||
.location(new Point(74.6514, 40.3340))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Campus Yale = Campus.Builder.newInstance()
|
private final Campus Yale = Campus.Builder.newInstance().id("campus:Yale").name("Yale").location(new Point(72.9223, 41.3163)).build();
|
||||||
.id("campus:Yale")
|
|
||||||
.name("Yale")
|
|
||||||
.location(new Point(72.9223, 41.3163))
|
|
||||||
.build();
|
|
||||||
|
|
||||||
private final Point Boston = new Point(71.0589, 42.3601);
|
private final Point Boston = new Point(71.0589, 42.3601);
|
||||||
private final Point NewYorkCity = new Point(74.0059, 40.7128);
|
private final Point NewYorkCity = new Point(74.0059, 40.7128);
|
||||||
|
@ -31,24 +31,14 @@ public class StudentServiceImplTest extends MultiBucketIntegationTest {
|
|||||||
static final String joeCollegeId = "student:" + joe + ":" + college;
|
static final String joeCollegeId = "student:" + joe + ":" + college;
|
||||||
static final DateTime joeCollegeDob = DateTime.now().minusYears(21);
|
static final DateTime joeCollegeDob = DateTime.now().minusYears(21);
|
||||||
static final Student joeCollege = new Student(joeCollegeId, joe, college, joeCollegeDob);
|
static final Student joeCollege = new Student(joeCollegeId, joe, college, joeCollegeDob);
|
||||||
static final JsonObject jsonJoeCollege = JsonObject.empty()
|
static final JsonObject jsonJoeCollege = JsonObject.empty().put(typeField, Student.class.getName()).put("firstName", joe).put("lastName", college).put("created", DateTime.now().getMillis()).put("version", 1);
|
||||||
.put(typeField, Student.class.getName())
|
|
||||||
.put("firstName", joe)
|
|
||||||
.put("lastName", college)
|
|
||||||
.put("created", DateTime.now().getMillis())
|
|
||||||
.put("version", 1);
|
|
||||||
|
|
||||||
static final String judy = "Judy";
|
static final String judy = "Judy";
|
||||||
static final String jetson = "Jetson";
|
static final String jetson = "Jetson";
|
||||||
static final String judyJetsonId = "student:" + judy + ":" + jetson;
|
static final String judyJetsonId = "student:" + judy + ":" + jetson;
|
||||||
static final DateTime judyJetsonDob = DateTime.now().minusYears(19).minusMonths(5).minusDays(3);
|
static final DateTime judyJetsonDob = DateTime.now().minusYears(19).minusMonths(5).minusDays(3);
|
||||||
static final Student judyJetson = new Student(judyJetsonId, judy, jetson, judyJetsonDob);
|
static final Student judyJetson = new Student(judyJetsonId, judy, jetson, judyJetsonDob);
|
||||||
static final JsonObject jsonJudyJetson = JsonObject.empty()
|
static final JsonObject jsonJudyJetson = JsonObject.empty().put(typeField, Student.class.getName()).put("firstName", judy).put("lastName", jetson).put("created", DateTime.now().getMillis()).put("version", 1);
|
||||||
.put(typeField, Student.class.getName())
|
|
||||||
.put("firstName", judy)
|
|
||||||
.put("lastName", jetson)
|
|
||||||
.put("created", DateTime.now().getMillis())
|
|
||||||
.put("version", 1);
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
StudentServiceImpl studentService;
|
StudentServiceImpl studentService;
|
||||||
|
@ -43,8 +43,7 @@ public class ElasticSearchUnitTests {
|
|||||||
@Test
|
@Test
|
||||||
public void givenJsonString_whenJavaObject_thenIndexDocument() {
|
public void givenJsonString_whenJavaObject_thenIndexDocument() {
|
||||||
String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}";
|
String jsonObject = "{\"age\":20,\"dateOfBirth\":1471466076564,\"fullName\":\"John Doe\"}";
|
||||||
IndexResponse response = client.prepareIndex("people", "Doe")
|
IndexResponse response = client.prepareIndex("people", "Doe").setSource(jsonObject).get();
|
||||||
.setSource(jsonObject).get();
|
|
||||||
String index = response.getIndex();
|
String index = response.getIndex();
|
||||||
String type = response.getType();
|
String type = response.getType();
|
||||||
assertTrue(response.isCreated());
|
assertTrue(response.isCreated());
|
||||||
@ -55,8 +54,7 @@ public class ElasticSearchUnitTests {
|
|||||||
@Test
|
@Test
|
||||||
public void givenDocumentId_whenJavaObject_thenDeleteDocument() {
|
public void givenDocumentId_whenJavaObject_thenDeleteDocument() {
|
||||||
String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}";
|
String jsonObject = "{\"age\":10,\"dateOfBirth\":1471455886564,\"fullName\":\"Johan Doe\"}";
|
||||||
IndexResponse response = client.prepareIndex("people", "Doe")
|
IndexResponse response = client.prepareIndex("people", "Doe").setSource(jsonObject).get();
|
||||||
.setSource(jsonObject).get();
|
|
||||||
String id = response.getId();
|
String id = response.getId();
|
||||||
DeleteResponse deleteResponse = client.prepareDelete("people", "Doe", id).get();
|
DeleteResponse deleteResponse = client.prepareDelete("people", "Doe", id).get();
|
||||||
assertTrue(deleteResponse.isFound());
|
assertTrue(deleteResponse.isFound());
|
||||||
@ -77,29 +75,11 @@ public class ElasticSearchUnitTests {
|
|||||||
@Test
|
@Test
|
||||||
public void givenSearchParamters_thenReturnResults() {
|
public void givenSearchParamters_thenReturnResults() {
|
||||||
boolean isExecutedSuccessfully = true;
|
boolean isExecutedSuccessfully = true;
|
||||||
SearchResponse response = client.prepareSearch()
|
SearchResponse response = client.prepareSearch().setTypes().setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setPostFilter(QueryBuilders.rangeQuery("age").from(5).to(15)).setFrom(0).setSize(60).setExplain(true).execute().actionGet();
|
||||||
.setTypes()
|
|
||||||
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
|
|
||||||
.setPostFilter(QueryBuilders.rangeQuery("age").from(5).to(15))
|
|
||||||
.setFrom(0).setSize(60).setExplain(true)
|
|
||||||
.execute()
|
|
||||||
.actionGet();
|
|
||||||
|
|
||||||
SearchResponse response2 = client.prepareSearch()
|
SearchResponse response2 = client.prepareSearch().setTypes().setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setPostFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette")).setFrom(0).setSize(60).setExplain(true).execute().actionGet();
|
||||||
.setTypes()
|
|
||||||
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
|
|
||||||
.setPostFilter(QueryBuilders.simpleQueryStringQuery("+John -Doe OR Janette"))
|
|
||||||
.setFrom(0).setSize(60).setExplain(true)
|
|
||||||
.execute()
|
|
||||||
.actionGet();
|
|
||||||
|
|
||||||
SearchResponse response3 = client.prepareSearch()
|
SearchResponse response3 = client.prepareSearch().setTypes().setSearchType(SearchType.DFS_QUERY_THEN_FETCH).setPostFilter(QueryBuilders.matchQuery("John", "Name*")).setFrom(0).setSize(60).setExplain(true).execute().actionGet();
|
||||||
.setTypes()
|
|
||||||
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
|
|
||||||
.setPostFilter(QueryBuilders.matchQuery("John", "Name*"))
|
|
||||||
.setFrom(0).setSize(60).setExplain(true)
|
|
||||||
.execute()
|
|
||||||
.actionGet();
|
|
||||||
try {
|
try {
|
||||||
response2.getHits();
|
response2.getHits();
|
||||||
response3.getHits();
|
response3.getHits();
|
||||||
@ -114,14 +94,8 @@ public class ElasticSearchUnitTests {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException {
|
public void givenContentBuilder_whenHelpers_thanIndexJson() throws IOException {
|
||||||
XContentBuilder builder = XContentFactory.jsonBuilder()
|
XContentBuilder builder = XContentFactory.jsonBuilder().startObject().field("fullName", "Test").field("salary", "11500").field("age", "10").endObject();
|
||||||
.startObject()
|
IndexResponse response = client.prepareIndex("people", "Doe").setSource(builder).get();
|
||||||
.field("fullName", "Test")
|
|
||||||
.field("salary", "11500")
|
|
||||||
.field("age", "10")
|
|
||||||
.endObject();
|
|
||||||
IndexResponse response = client.prepareIndex("people", "Doe")
|
|
||||||
.setSource(builder).get();
|
|
||||||
assertTrue(response.isCreated());
|
assertTrue(response.isCreated());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,6 @@ import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
|
|||||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
|
||||||
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
|
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
|
||||||
@Configuration
|
@Configuration
|
||||||
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory")
|
@EnableNeo4jRepositories(basePackages = "com.baeldung.spring.data.neo4j.repostory")
|
||||||
@ -20,10 +19,7 @@ public class MovieDatabaseNeo4jConfiguration extends Neo4jConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
public org.neo4j.ogm.config.Configuration getConfiguration() {
|
public org.neo4j.ogm.config.Configuration getConfiguration() {
|
||||||
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
|
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
|
||||||
config
|
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver").setURI(URL);
|
||||||
.driverConfiguration()
|
|
||||||
.setDriverClassName("org.neo4j.ogm.drivers.http.driver.HttpDriver")
|
|
||||||
.setURI(URL);
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,6 @@ import org.springframework.data.neo4j.repository.config.EnableNeo4jRepositories;
|
|||||||
import org.springframework.data.neo4j.server.Neo4jServer;
|
import org.springframework.data.neo4j.server.Neo4jServer;
|
||||||
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
import org.springframework.transaction.annotation.EnableTransactionManagement;
|
||||||
|
|
||||||
|
|
||||||
@EnableTransactionManagement
|
@EnableTransactionManagement
|
||||||
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
|
@ComponentScan(basePackages = { "com.baeldung.spring.data.neo4j.services" })
|
||||||
@Configuration
|
@Configuration
|
||||||
@ -21,9 +20,7 @@ public class MovieDatabaseNeo4jTestConfiguration extends Neo4jConfiguration {
|
|||||||
@Bean
|
@Bean
|
||||||
public org.neo4j.ogm.config.Configuration getConfiguration() {
|
public org.neo4j.ogm.config.Configuration getConfiguration() {
|
||||||
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
|
org.neo4j.ogm.config.Configuration config = new org.neo4j.ogm.config.Configuration();
|
||||||
config
|
config.driverConfiguration().setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
|
||||||
.driverConfiguration()
|
|
||||||
.setDriverClassName("org.neo4j.ogm.drivers.embedded.driver.EmbeddedDriver");
|
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,9 +21,11 @@ public class Movie {
|
|||||||
private int released;
|
private int released;
|
||||||
private String tagline;
|
private String tagline;
|
||||||
|
|
||||||
@Relationship(type="ACTED_IN", direction = Relationship.INCOMING) private List<Role> roles;
|
@Relationship(type = "ACTED_IN", direction = Relationship.INCOMING)
|
||||||
|
private List<Role> roles;
|
||||||
|
|
||||||
public Movie() { }
|
public Movie() {
|
||||||
|
}
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
@ -57,5 +59,4 @@ public class Movie {
|
|||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.baeldung.spring.data.neo4j.domain;
|
package com.baeldung.spring.data.neo4j.domain;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
import com.voodoodyne.jackson.jsog.JSOGGenerator;
|
import com.voodoodyne.jackson.jsog.JSOGGenerator;
|
||||||
import org.neo4j.ogm.annotation.GraphId;
|
import org.neo4j.ogm.annotation.GraphId;
|
||||||
@ -21,7 +20,8 @@ public class Person {
|
|||||||
@Relationship(type = "ACTED_IN")
|
@Relationship(type = "ACTED_IN")
|
||||||
private List<Movie> movies;
|
private List<Movie> movies;
|
||||||
|
|
||||||
public Person() { }
|
public Person() {
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.baeldung.spring.data.neo4j.domain;
|
package com.baeldung.spring.data.neo4j.domain;
|
||||||
|
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
|
||||||
import com.voodoodyne.jackson.jsog.JSOGGenerator;
|
import com.voodoodyne.jackson.jsog.JSOGGenerator;
|
||||||
import org.neo4j.ogm.annotation.EndNode;
|
import org.neo4j.ogm.annotation.EndNode;
|
||||||
|
@ -20,5 +20,3 @@ public interface MovieRepository extends GraphRepository<Movie> {
|
|||||||
@Query("MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) RETURN m.title as movie, collect(a.name) as cast LIMIT {limit}")
|
@Query("MATCH (m:Movie)<-[:ACTED_IN]-(a:Person) RETURN m.title as movie, collect(a.name) as cast LIMIT {limit}")
|
||||||
List<Map<String, Object>> graph(@Param("limit") int limit);
|
List<Map<String, Object>> graph(@Param("limit") int limit);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import com.baeldung.spring.data.neo4j.domain.Person;
|
|||||||
import org.springframework.data.neo4j.repository.GraphRepository;
|
import org.springframework.data.neo4j.repository.GraphRepository;
|
||||||
import org.springframework.stereotype.Repository;
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|
||||||
@Repository
|
@Repository
|
||||||
public interface PersonRepository extends GraphRepository<Person> {
|
public interface PersonRepository extends GraphRepository<Person> {
|
||||||
|
|
||||||
|
@ -82,8 +82,7 @@ public class MovieRepositoryTest {
|
|||||||
@DirtiesContext
|
@DirtiesContext
|
||||||
public void testFindAll() {
|
public void testFindAll() {
|
||||||
System.out.println("findAll");
|
System.out.println("findAll");
|
||||||
Collection<Movie> result =
|
Collection<Movie> result = (Collection<Movie>) movieRepository.findAll();
|
||||||
(Collection<Movie>) movieRepository.findAll();
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
}
|
}
|
||||||
@ -93,8 +92,7 @@ public class MovieRepositoryTest {
|
|||||||
public void testFindByTitleContaining() {
|
public void testFindByTitleContaining() {
|
||||||
System.out.println("findByTitleContaining");
|
System.out.println("findByTitleContaining");
|
||||||
String title = "Italian";
|
String title = "Italian";
|
||||||
Collection<Movie> result =
|
Collection<Movie> result = movieRepository.findByTitleContaining(title);
|
||||||
movieRepository.findByTitleContaining(title);
|
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(1, result.size());
|
assertEquals(1, result.size());
|
||||||
}
|
}
|
||||||
@ -126,8 +124,7 @@ public class MovieRepositoryTest {
|
|||||||
public void testDeleteAll() {
|
public void testDeleteAll() {
|
||||||
System.out.println("deleteAll");
|
System.out.println("deleteAll");
|
||||||
movieRepository.deleteAll();
|
movieRepository.deleteAll();
|
||||||
Collection<Movie> result =
|
Collection<Movie> result = (Collection<Movie>) movieRepository.findAll();
|
||||||
(Collection<Movie>) movieRepository.findAll();
|
|
||||||
assertEquals(0, result.size());
|
assertEquals(0, result.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.baeldung.spring.data.redis.queue;
|
package com.baeldung.spring.data.redis.queue;
|
||||||
|
|
||||||
|
|
||||||
public interface MessagePublisher {
|
public interface MessagePublisher {
|
||||||
|
|
||||||
void publish(final String message);
|
void publish(final String message);
|
||||||
|
@ -16,8 +16,7 @@ public class RedisMessagePublisher implements MessagePublisher {
|
|||||||
public RedisMessagePublisher() {
|
public RedisMessagePublisher() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public RedisMessagePublisher(final RedisTemplate<String, Object> redisTemplate,
|
public RedisMessagePublisher(final RedisTemplate<String, Object> redisTemplate, final ChannelTopic topic) {
|
||||||
final ChannelTopic topic) {
|
|
||||||
this.redisTemplate = redisTemplate;
|
this.redisTemplate = redisTemplate;
|
||||||
this.topic = topic;
|
this.topic = topic;
|
||||||
}
|
}
|
||||||
|
@ -9,8 +9,7 @@ public class HibernateUtil {
|
|||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
public static Session getHibernateSession() {
|
public static Session getHibernateSession() {
|
||||||
|
|
||||||
final SessionFactory sf = new Configuration()
|
final SessionFactory sf = new Configuration().configure("criteria.cfg.xml").buildSessionFactory();
|
||||||
.configure("criteria.cfg.xml").buildSessionFactory();
|
|
||||||
|
|
||||||
// factory = new Configuration().configure().buildSessionFactory();
|
// factory = new Configuration().configure().buildSessionFactory();
|
||||||
final Session session = sf.openSession();
|
final Session session = sf.openSession();
|
||||||
|
@ -226,8 +226,7 @@ public class ApplicationView {
|
|||||||
// Set projections Row Count
|
// Set projections Row Count
|
||||||
public Long[] projectionRowCount() {
|
public Long[] projectionRowCount() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Long> itemProjected = session.createCriteria(Item.class).setProjection(Projections.rowCount())
|
final List<Long> itemProjected = session.createCriteria(Item.class).setProjection(Projections.rowCount()).list();
|
||||||
.list();
|
|
||||||
final Long projectedRowCount[] = new Long[itemProjected.size()];
|
final Long projectedRowCount[] = new Long[itemProjected.size()];
|
||||||
for (int i = 0; i < itemProjected.size(); i++) {
|
for (int i = 0; i < itemProjected.size(); i++) {
|
||||||
projectedRowCount[i] = itemProjected.get(i);
|
projectedRowCount[i] = itemProjected.get(i);
|
||||||
@ -239,8 +238,7 @@ public class ApplicationView {
|
|||||||
// Set projections average of itemPrice
|
// Set projections average of itemPrice
|
||||||
public Double[] projectionAverage() {
|
public Double[] projectionAverage() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List avgItemPriceList = session.createCriteria(Item.class)
|
final List avgItemPriceList = session.createCriteria(Item.class).setProjection(Projections.projectionList().add(Projections.avg("itemPrice"))).list();
|
||||||
.setProjection(Projections.projectionList().add(Projections.avg("itemPrice"))).list();
|
|
||||||
|
|
||||||
final Double avgItemPrice[] = new Double[avgItemPriceList.size()];
|
final Double avgItemPrice[] = new Double[avgItemPriceList.size()];
|
||||||
for (int i = 0; i < avgItemPriceList.size(); i++) {
|
for (int i = 0; i < avgItemPriceList.size(); i++) {
|
||||||
|
@ -29,6 +29,7 @@ public class OrderDetail implements Serializable{
|
|||||||
result = prime * result + ((orderId == null) ? 0 : orderId.hashCode());
|
result = prime * result + ((orderId == null) ? 0 : orderId.hashCode());
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object obj) {
|
public boolean equals(Object obj) {
|
||||||
if (this == obj)
|
if (this == obj)
|
||||||
@ -50,9 +51,8 @@ public class OrderDetail implements Serializable{
|
|||||||
public Long getOrderId() {
|
public Long getOrderId() {
|
||||||
return orderId;
|
return orderId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOrderId(Long orderId) {
|
public void setOrderId(Long orderId) {
|
||||||
this.orderId = orderId;
|
this.orderId = orderId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,7 +60,6 @@ public class UserLazy implements Serializable {
|
|||||||
this.userId = userId;
|
this.userId = userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Set<OrderDetail> getOrderDetail() {
|
public Set<OrderDetail> getOrderDetail() {
|
||||||
return orderDetail;
|
return orderDetail;
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,7 @@ public class HibernateUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Session getHibernateSession() {
|
public static Session getHibernateSession() {
|
||||||
return new Configuration()
|
return new Configuration().configure("fetching.cfg.xml").buildSessionFactory().openSession();
|
||||||
.configure("fetching.cfg.xml")
|
|
||||||
.buildSessionFactory()
|
|
||||||
.openSession();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,7 @@ import javax.persistence.NamedNativeQuery;
|
|||||||
|
|
||||||
import org.hibernate.envers.Audited;
|
import org.hibernate.envers.Audited;
|
||||||
|
|
||||||
@NamedNativeQueries({
|
@NamedNativeQueries({ @NamedNativeQuery(name = "callGetAllFoos", query = "CALL GetAllFoos()", resultClass = Foo.class), @NamedNativeQuery(name = "callGetFoosByName", query = "CALL GetFoosByName(:fooName)", resultClass = Foo.class) })
|
||||||
@NamedNativeQuery(name = "callGetAllFoos", query = "CALL GetAllFoos()", resultClass = Foo.class),
|
|
||||||
@NamedNativeQuery(name = "callGetFoosByName", query = "CALL GetFoosByName(:fooName)", resultClass = Foo.class) })
|
|
||||||
@Entity
|
@Entity
|
||||||
@Audited
|
@Audited
|
||||||
// @Proxy(lazy = false)
|
// @Proxy(lazy = false)
|
||||||
|
@ -49,8 +49,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testNullCriteriaQuery() {
|
public void testNullCriteriaQuery() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Item> expectedIsNullDescItemsList = session.createQuery("From Item where itemDescription is null")
|
final List<Item> expectedIsNullDescItemsList = session.createQuery("From Item where itemDescription is null").list();
|
||||||
.list();
|
|
||||||
final String expectedIsNullDescItems[] = new String[expectedIsNullDescItemsList.size()];
|
final String expectedIsNullDescItems[] = new String[expectedIsNullDescItemsList.size()];
|
||||||
for (int i = 0; i < expectedIsNullDescItemsList.size(); i++) {
|
for (int i = 0; i < expectedIsNullDescItemsList.size(); i++) {
|
||||||
expectedIsNullDescItems[i] = expectedIsNullDescItemsList.get(i).getItemName();
|
expectedIsNullDescItems[i] = expectedIsNullDescItemsList.get(i).getItemName();
|
||||||
@ -62,8 +61,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsNotNullCriteriaQuery() {
|
public void testIsNotNullCriteriaQuery() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Item> expectedIsNotNullDescItemsList = session
|
final List<Item> expectedIsNotNullDescItemsList = session.createQuery("From Item where itemDescription is not null").list();
|
||||||
.createQuery("From Item where itemDescription is not null").list();
|
|
||||||
final String expectedIsNotNullDescItems[] = new String[expectedIsNotNullDescItemsList.size()];
|
final String expectedIsNotNullDescItems[] = new String[expectedIsNotNullDescItemsList.size()];
|
||||||
for (int i = 0; i < expectedIsNotNullDescItemsList.size(); i++) {
|
for (int i = 0; i < expectedIsNotNullDescItemsList.size(); i++) {
|
||||||
expectedIsNotNullDescItems[i] = expectedIsNotNullDescItemsList.get(i).getItemName();
|
expectedIsNotNullDescItems[i] = expectedIsNotNullDescItemsList.get(i).getItemName();
|
||||||
@ -76,8 +74,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAverageProjection() {
|
public void testAverageProjection() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Double> expectedAvgProjItemsList = session.createQuery("Select avg(itemPrice) from Item item")
|
final List<Double> expectedAvgProjItemsList = session.createQuery("Select avg(itemPrice) from Item item").list();
|
||||||
.list();
|
|
||||||
|
|
||||||
final Double expectedAvgProjItems[] = new Double[expectedAvgProjItemsList.size()];
|
final Double expectedAvgProjItems[] = new Double[expectedAvgProjItemsList.size()];
|
||||||
for (int i = 0; i < expectedAvgProjItemsList.size(); i++) {
|
for (int i = 0; i < expectedAvgProjItemsList.size(); i++) {
|
||||||
@ -103,8 +100,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testOrCriteriaQuery() {
|
public void testOrCriteriaQuery() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Item> expectedOrCritItemsList = session
|
final List<Item> expectedOrCritItemsList = session.createQuery("From Item where itemPrice>1000 or itemName like 'Chair%'").list();
|
||||||
.createQuery("From Item where itemPrice>1000 or itemName like 'Chair%'").list();
|
|
||||||
final String expectedOrCritItems[] = new String[expectedOrCritItemsList.size()];
|
final String expectedOrCritItems[] = new String[expectedOrCritItemsList.size()];
|
||||||
for (int i = 0; i < expectedOrCritItemsList.size(); i++) {
|
for (int i = 0; i < expectedOrCritItemsList.size(); i++) {
|
||||||
expectedOrCritItems[i] = expectedOrCritItemsList.get(i).getItemName();
|
expectedOrCritItems[i] = expectedOrCritItemsList.get(i).getItemName();
|
||||||
@ -116,8 +112,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAndCriteriaQuery() {
|
public void testAndCriteriaQuery() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Item> expectedAndCritItemsList = session
|
final List<Item> expectedAndCritItemsList = session.createQuery("From Item where itemPrice>1000 and itemName like 'Chair%'").list();
|
||||||
.createQuery("From Item where itemPrice>1000 and itemName like 'Chair%'").list();
|
|
||||||
final String expectedAndCritItems[] = new String[expectedAndCritItemsList.size()];
|
final String expectedAndCritItems[] = new String[expectedAndCritItemsList.size()];
|
||||||
for (int i = 0; i < expectedAndCritItemsList.size(); i++) {
|
for (int i = 0; i < expectedAndCritItemsList.size(); i++) {
|
||||||
expectedAndCritItems[i] = expectedAndCritItemsList.get(i).getItemName();
|
expectedAndCritItems[i] = expectedAndCritItemsList.get(i).getItemName();
|
||||||
@ -129,8 +124,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testMultiCriteriaQuery() {
|
public void testMultiCriteriaQuery() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Item> expectedMultiCritItemsList = session
|
final List<Item> expectedMultiCritItemsList = session.createQuery("From Item where itemDescription is null and itemName like'chair%'").list();
|
||||||
.createQuery("From Item where itemDescription is null and itemName like'chair%'").list();
|
|
||||||
final String expectedMultiCritItems[] = new String[expectedMultiCritItemsList.size()];
|
final String expectedMultiCritItems[] = new String[expectedMultiCritItemsList.size()];
|
||||||
for (int i = 0; i < expectedMultiCritItemsList.size(); i++) {
|
for (int i = 0; i < expectedMultiCritItemsList.size(); i++) {
|
||||||
expectedMultiCritItems[i] = expectedMultiCritItemsList.get(i).getItemName();
|
expectedMultiCritItems[i] = expectedMultiCritItemsList.get(i).getItemName();
|
||||||
@ -142,8 +136,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testSortCriteriaQuery() {
|
public void testSortCriteriaQuery() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Item> expectedSortCritItemsList = session
|
final List<Item> expectedSortCritItemsList = session.createQuery("From Item order by itemName asc, itemPrice desc").list();
|
||||||
.createQuery("From Item order by itemName asc, itemPrice desc").list();
|
|
||||||
final String expectedSortCritItems[] = new String[expectedSortCritItemsList.size()];
|
final String expectedSortCritItems[] = new String[expectedSortCritItemsList.size()];
|
||||||
for (int i = 0; i < expectedSortCritItemsList.size(); i++) {
|
for (int i = 0; i < expectedSortCritItemsList.size(); i++) {
|
||||||
expectedSortCritItems[i] = expectedSortCritItemsList.get(i).getItemName();
|
expectedSortCritItems[i] = expectedSortCritItemsList.get(i).getItemName();
|
||||||
@ -179,8 +172,7 @@ public class HibernateCriteriaTest {
|
|||||||
@Test
|
@Test
|
||||||
public void betweenCriteriaQuery() {
|
public void betweenCriteriaQuery() {
|
||||||
final Session session = HibernateUtil.getHibernateSession();
|
final Session session = HibernateUtil.getHibernateSession();
|
||||||
final List<Item> expectedBetweenList = session.createQuery("From Item where itemPrice between 100 and 200")
|
final List<Item> expectedBetweenList = session.createQuery("From Item where itemPrice between 100 and 200").list();
|
||||||
.list();
|
|
||||||
final String expectedPriceBetweenItems[] = new String[expectedBetweenList.size()];
|
final String expectedPriceBetweenItems[] = new String[expectedBetweenList.size()];
|
||||||
for (int i = 0; i < expectedBetweenList.size(); i++) {
|
for (int i = 0; i < expectedBetweenList.size(); i++) {
|
||||||
expectedPriceBetweenItems[i] = expectedBetweenList.get(i).getItemName();
|
expectedPriceBetweenItems[i] = expectedBetweenList.get(i).getItemName();
|
||||||
|
@ -13,7 +13,6 @@ import static org.junit.Assert.assertTrue;
|
|||||||
|
|
||||||
public class HibernateFetchingTest {
|
public class HibernateFetchingTest {
|
||||||
|
|
||||||
|
|
||||||
// this loads sample data in the database
|
// this loads sample data in the database
|
||||||
@Before
|
@Before
|
||||||
public void addFecthingTestData() {
|
public void addFecthingTestData() {
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
package com.baeldung.persistence.save;
|
package com.baeldung.persistence.save;
|
||||||
|
|
||||||
|
|
||||||
import com.baeldung.persistence.model.Person;
|
import com.baeldung.persistence.model.Person;
|
||||||
import org.hibernate.HibernateException;
|
import org.hibernate.HibernateException;
|
||||||
import org.hibernate.Session;
|
import org.hibernate.Session;
|
||||||
@ -25,16 +24,9 @@ public class SaveMethodsTest {
|
|||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void beforeTests() {
|
public static void beforeTests() {
|
||||||
Configuration configuration = new Configuration()
|
Configuration configuration = new Configuration().addAnnotatedClass(Person.class).setProperty("hibernate.dialect", HSQLDialect.class.getName()).setProperty("hibernate.connection.driver_class", org.hsqldb.jdbcDriver.class.getName())
|
||||||
.addAnnotatedClass(Person.class)
|
.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test").setProperty("hibernate.connection.username", "sa").setProperty("hibernate.connection.password", "").setProperty("hibernate.hbm2ddl.auto", "update");
|
||||||
.setProperty("hibernate.dialect", HSQLDialect.class.getName())
|
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(configuration.getProperties()).build();
|
||||||
.setProperty("hibernate.connection.driver_class", org.hsqldb.jdbcDriver.class.getName())
|
|
||||||
.setProperty("hibernate.connection.url", "jdbc:hsqldb:mem:test")
|
|
||||||
.setProperty("hibernate.connection.username", "sa")
|
|
||||||
.setProperty("hibernate.connection.password", "")
|
|
||||||
.setProperty("hibernate.hbm2ddl.auto", "update");
|
|
||||||
ServiceRegistry serviceRegistry = new StandardServiceRegistryBuilder().applySettings(
|
|
||||||
configuration.getProperties()).build();
|
|
||||||
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,7 +36,6 @@ public class SaveMethodsTest {
|
|||||||
session.beginTransaction();
|
session.beginTransaction();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenPersistTransient_thenSavedToDatabaseOnCommit() {
|
public void whenPersistTransient_thenSavedToDatabaseOnCommit() {
|
||||||
|
|
||||||
@ -244,7 +235,6 @@ public class SaveMethodsTest {
|
|||||||
|
|
||||||
assertNotNull(session.get(Person.class, person.getId()));
|
assertNotNull(session.get(Person.class, person.getId()));
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -47,8 +47,7 @@ public class FooStoredProceduresIntegrationTest {
|
|||||||
|
|
||||||
private boolean getFoosByNameExists() {
|
private boolean getFoosByNameExists() {
|
||||||
try {
|
try {
|
||||||
Query sqlQuery = session.createSQLQuery("CALL GetAllFoos()")
|
Query sqlQuery = session.createSQLQuery("CALL GetAllFoos()").addEntity(Foo.class);
|
||||||
.addEntity(Foo.class);
|
|
||||||
sqlQuery.list();
|
sqlQuery.list();
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLGrammarException e) {
|
} catch (SQLGrammarException e) {
|
||||||
@ -59,8 +58,7 @@ public class FooStoredProceduresIntegrationTest {
|
|||||||
|
|
||||||
private boolean getAllFoosExists() {
|
private boolean getAllFoosExists() {
|
||||||
try {
|
try {
|
||||||
Query sqlQuery = session.createSQLQuery("CALL GetAllFoos()")
|
Query sqlQuery = session.createSQLQuery("CALL GetAllFoos()").addEntity(Foo.class);
|
||||||
.addEntity(Foo.class);
|
|
||||||
sqlQuery.list();
|
sqlQuery.list();
|
||||||
return true;
|
return true;
|
||||||
} catch (SQLGrammarException e) {
|
} catch (SQLGrammarException e) {
|
||||||
@ -80,8 +78,7 @@ public class FooStoredProceduresIntegrationTest {
|
|||||||
fooService.create(new Foo(randomAlphabetic(6)));
|
fooService.create(new Foo(randomAlphabetic(6)));
|
||||||
|
|
||||||
// Stored procedure getAllFoos using createSQLQuery
|
// Stored procedure getAllFoos using createSQLQuery
|
||||||
Query sqlQuery = session.createSQLQuery("CALL GetAllFoos()").addEntity(
|
Query sqlQuery = session.createSQLQuery("CALL GetAllFoos()").addEntity(Foo.class);
|
||||||
Foo.class);
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Foo> allFoos = sqlQuery.list();
|
List<Foo> allFoos = sqlQuery.list();
|
||||||
for (Foo foo : allFoos) {
|
for (Foo foo : allFoos) {
|
||||||
@ -105,8 +102,7 @@ public class FooStoredProceduresIntegrationTest {
|
|||||||
fooService.create(new Foo("NewFooName"));
|
fooService.create(new Foo("NewFooName"));
|
||||||
|
|
||||||
// Stored procedure getFoosByName using createSQLQuery()
|
// Stored procedure getFoosByName using createSQLQuery()
|
||||||
Query sqlQuery = session.createSQLQuery("CALL GetFoosByName(:fooName)")
|
Query sqlQuery = session.createSQLQuery("CALL GetFoosByName(:fooName)").addEntity(Foo.class).setParameter("fooName", "NewFooName");
|
||||||
.addEntity(Foo.class).setParameter("fooName", "NewFooName");
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Foo> allFoosByName = sqlQuery.list();
|
List<Foo> allFoosByName = sqlQuery.list();
|
||||||
for (Foo foo : allFoosByName) {
|
for (Foo foo : allFoosByName) {
|
||||||
@ -114,8 +110,7 @@ public class FooStoredProceduresIntegrationTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Stored procedure getFoosByName using getNamedQuery()
|
// Stored procedure getFoosByName using getNamedQuery()
|
||||||
Query namedQuery = session.getNamedQuery("callGetFoosByName")
|
Query namedQuery = session.getNamedQuery("callGetFoosByName").setParameter("fooName", "NewFooName");
|
||||||
.setParameter("fooName", "NewFooName");
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
List<Foo> allFoosByName2 = namedQuery.list();
|
List<Foo> allFoosByName2 = namedQuery.list();
|
||||||
for (Foo foo : allFoosByName2) {
|
for (Foo foo : allFoosByName2) {
|
||||||
|
@ -12,8 +12,7 @@ public class DefaultTextMessageSenderTest {
|
|||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:EmbeddedActiveMQ.xml", "classpath:applicationContext.xml");
|
||||||
"classpath:EmbeddedActiveMQ.xml", "classpath:applicationContext.xml");
|
|
||||||
messageProducer = (SampleJmsMessageSender) applicationContext.getBean("SampleJmsMessageSender");
|
messageProducer = (SampleJmsMessageSender) applicationContext.getBean("SampleJmsMessageSender");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,8 +12,7 @@ public class MapMessageConvertAndSendTest {
|
|||||||
@SuppressWarnings("resource")
|
@SuppressWarnings("resource")
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() {
|
public static void setUp() {
|
||||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext(
|
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:EmbeddedActiveMQ.xml", "classpath:applicationContext.xml");
|
||||||
"classpath:EmbeddedActiveMQ.xml", "classpath:applicationContext.xml");
|
|
||||||
messageProducer = (SampleJmsMessageSender) applicationContext.getBean("SampleJmsMessageSender");
|
messageProducer = (SampleJmsMessageSender) applicationContext.getBean("SampleJmsMessageSender");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,7 @@ public class SecondLevelCacheIntegrationTest {
|
|||||||
final Foo foo = new Foo(randomAlphabetic(6));
|
final Foo foo = new Foo(randomAlphabetic(6));
|
||||||
fooService.create(foo);
|
fooService.create(foo);
|
||||||
fooService.findOne(foo.getId());
|
fooService.findOne(foo.getId());
|
||||||
final int size = CacheManager.ALL_CACHE_MANAGERS.get(0)
|
final int size = CacheManager.ALL_CACHE_MANAGERS.get(0).getCache("org.baeldung.persistence.model.Foo").getSize();
|
||||||
.getCache("org.baeldung.persistence.model.Foo").getSize();
|
|
||||||
assertThat(size, greaterThan(0));
|
assertThat(size, greaterThan(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,21 +63,17 @@ public class SecondLevelCacheIntegrationTest {
|
|||||||
return nativeQuery.executeUpdate();
|
return nativeQuery.executeUpdate();
|
||||||
});
|
});
|
||||||
|
|
||||||
final int size = CacheManager.ALL_CACHE_MANAGERS.get(0)
|
final int size = CacheManager.ALL_CACHE_MANAGERS.get(0).getCache("org.baeldung.persistence.model.Foo").getSize();
|
||||||
.getCache("org.baeldung.persistence.model.Foo").getSize();
|
|
||||||
assertThat(size, greaterThan(0));
|
assertThat(size, greaterThan(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public final void givenCacheableQueryIsExecuted_thenItIsCached() {
|
public final void givenCacheableQueryIsExecuted_thenItIsCached() {
|
||||||
new TransactionTemplate(platformTransactionManager).execute(status -> {
|
new TransactionTemplate(platformTransactionManager).execute(status -> {
|
||||||
return entityManager.createQuery("select f from Foo f")
|
return entityManager.createQuery("select f from Foo f").setHint("org.hibernate.cacheable", true).getResultList();
|
||||||
.setHint("org.hibernate.cacheable", true)
|
|
||||||
.getResultList();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final int size = CacheManager.ALL_CACHE_MANAGERS.get(0)
|
final int size = CacheManager.ALL_CACHE_MANAGERS.get(0).getCache("org.hibernate.cache.internal.StandardQueryCache").getSize();
|
||||||
.getCache("org.hibernate.cache.internal.StandardQueryCache").getSize();
|
|
||||||
assertThat(size, greaterThan(0));
|
assertThat(size, greaterThan(0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,7 +22,6 @@ public class MainController {
|
|||||||
return "index";
|
return "index";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
@RequestMapping(value = "/list", method = RequestMethod.GET)
|
||||||
public String listTutorialsPage(Model model) {
|
public String listTutorialsPage(Model model) {
|
||||||
List<Tutorial> list = tutService.listTutorials();
|
List<Tutorial> list = tutService.listTutorials();
|
||||||
@ -38,5 +37,4 @@ public class MainController {
|
|||||||
this.tutService = tutService;
|
this.tutService = tutService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
@ -10,9 +10,6 @@ import java.util.List;
|
|||||||
public class TutorialsService implements ITutorialsService {
|
public class TutorialsService implements ITutorialsService {
|
||||||
|
|
||||||
public List<Tutorial> listTutorials() {
|
public List<Tutorial> listTutorials() {
|
||||||
return Arrays.asList(
|
return Arrays.asList(new Tutorial(1, "Guava", "Introduction to Guava", "GuavaAuthor"), new Tutorial(2, "Android", "Introduction to Android", "AndroidAuthor"));
|
||||||
new Tutorial(1, "Guava", "Introduction to Guava", "GuavaAuthor"),
|
|
||||||
new Tutorial(2, "Android", "Introduction to Android", "AndroidAuthor")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -39,7 +39,6 @@ public class DataContentControllerTest {
|
|||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
|
|
||||||
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -9,7 +9,6 @@ import org.springframework.web.servlet.view.velocity.VelocityLayoutViewResolver;
|
|||||||
@Configuration
|
@Configuration
|
||||||
public class TestConfig {
|
public class TestConfig {
|
||||||
|
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public ViewResolver viewResolver() {
|
public ViewResolver viewResolver() {
|
||||||
final VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
|
final VelocityLayoutViewResolver bean = new VelocityLayoutViewResolver();
|
||||||
@ -27,6 +26,4 @@ public class TestConfig {
|
|||||||
return velocityConfigurer;
|
return velocityConfigurer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -11,8 +11,7 @@ public class HelloController extends AbstractController {
|
|||||||
@Override
|
@Override
|
||||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
ModelAndView model = new ModelAndView("helloworld");
|
ModelAndView model = new ModelAndView("helloworld");
|
||||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using SimpleUrlHandlerMapping.");
|
||||||
" using SimpleUrlHandlerMapping.");
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ public class HelloGuestController extends AbstractController {
|
|||||||
@Override
|
@Override
|
||||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
ModelAndView model = new ModelAndView("helloworld");
|
ModelAndView model = new ModelAndView("helloworld");
|
||||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using ControllerClassNameHandlerMapping.");
|
||||||
" using ControllerClassNameHandlerMapping.");
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -10,8 +10,7 @@ public class HelloWorldController extends AbstractController {
|
|||||||
@Override
|
@Override
|
||||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
ModelAndView model = new ModelAndView("helloworld");
|
ModelAndView model = new ModelAndView("helloworld");
|
||||||
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
model.addObject("msg", "Welcome to Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using BeanNameUrlHandlerMapping.");
|
||||||
" using BeanNameUrlHandlerMapping.");
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -33,8 +33,7 @@ public class PersonController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@RequestMapping(value = "/addPerson", method = RequestMethod.POST)
|
@RequestMapping(value = "/addPerson", method = RequestMethod.POST)
|
||||||
public String submit(@Valid @ModelAttribute("person") final Person person, final BindingResult result,
|
public String submit(@Valid @ModelAttribute("person") final Person person, final BindingResult result, final ModelMap modelMap, final Model model) {
|
||||||
final ModelMap modelMap, final Model model) {
|
|
||||||
|
|
||||||
validator.validate(person, result);
|
validator.validate(person, result);
|
||||||
|
|
||||||
|
@ -11,8 +11,7 @@ public class WelcomeController extends AbstractController {
|
|||||||
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
|
||||||
ModelAndView model = new ModelAndView("welcome");
|
ModelAndView model = new ModelAndView("welcome");
|
||||||
model.addObject("msg", " Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" +
|
model.addObject("msg", " Baeldung's Spring Handler Mappings Guide.<br>This request was mapped" + " using SimpleUrlHandlerMapping.");
|
||||||
" using SimpleUrlHandlerMapping.");
|
|
||||||
|
|
||||||
return model;
|
return model;
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,6 @@ import org.springframework.scheduling.annotation.EnableScheduling;
|
|||||||
public class SpringQuartzApp {
|
public class SpringQuartzApp {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
new SpringApplicationBuilder(SpringQuartzApp.class)
|
new SpringApplicationBuilder(SpringQuartzApp.class).showBanner(false).run(args);
|
||||||
.showBanner(false).run(args);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,7 @@ public class QrtzScheduler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
public Scheduler scheduler(Trigger trigger, JobDetail job)
|
public Scheduler scheduler(Trigger trigger, JobDetail job) throws SchedulerException, IOException {
|
||||||
throws SchedulerException, IOException {
|
|
||||||
|
|
||||||
StdSchedulerFactory factory = new StdSchedulerFactory();
|
StdSchedulerFactory factory = new StdSchedulerFactory();
|
||||||
factory.initialize(new ClassPathResource("quartz.properties").getInputStream());
|
factory.initialize(new ClassPathResource("quartz.properties").getInputStream());
|
||||||
@ -64,9 +63,7 @@ public class QrtzScheduler {
|
|||||||
@Bean
|
@Bean
|
||||||
public JobDetail jobDetail() {
|
public JobDetail jobDetail() {
|
||||||
|
|
||||||
return newJob().ofType(SampleJob.class).storeDurably()
|
return newJob().ofType(SampleJob.class).storeDurably().withIdentity(JobKey.jobKey("Qrtz_Job_Detail")).withDescription("Invoke Sample Job service...").build();
|
||||||
.withIdentity(JobKey.jobKey("Qrtz_Job_Detail"))
|
|
||||||
.withDescription("Invoke Sample Job service...").build();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Bean
|
@Bean
|
||||||
@ -75,10 +72,6 @@ public class QrtzScheduler {
|
|||||||
int frequencyInSec = 10;
|
int frequencyInSec = 10;
|
||||||
logger.info("Configuring trigger to fire every {} seconds", frequencyInSec);
|
logger.info("Configuring trigger to fire every {} seconds", frequencyInSec);
|
||||||
|
|
||||||
return newTrigger().forJob(job).withIdentity(TriggerKey.triggerKey("Qrtz_Trigger"))
|
return newTrigger().forJob(job).withIdentity(TriggerKey.triggerKey("Qrtz_Trigger")).withDescription("Sample trigger").withSchedule(simpleSchedule().withIntervalInSeconds(frequencyInSec).repeatForever()).build();
|
||||||
.withDescription("Sample trigger")
|
|
||||||
.withSchedule(
|
|
||||||
simpleSchedule().withIntervalInSeconds(frequencyInSec).repeatForever())
|
|
||||||
.build();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ public class SampleJob implements Job {
|
|||||||
|
|
||||||
public void execute(JobExecutionContext context) throws JobExecutionException {
|
public void execute(JobExecutionContext context) throws JobExecutionException {
|
||||||
|
|
||||||
logger.info("Job ** {} ** fired @ {}", context.getJobDetail().getKey().getName(),
|
logger.info("Job ** {} ** fired @ {}", context.getJobDetail().getKey().getName(), context.getFireTime());
|
||||||
context.getFireTime());
|
|
||||||
|
|
||||||
jobService.executeSampleJob();
|
jobService.executeSampleJob();
|
||||||
|
|
||||||
|
@ -11,21 +11,17 @@ import org.springframework.scheduling.quartz.SpringBeanJobFactory;
|
|||||||
* Adds auto-wiring support to quartz jobs.
|
* Adds auto-wiring support to quartz jobs.
|
||||||
* @see "https://gist.github.com/jelies/5085593"
|
* @see "https://gist.github.com/jelies/5085593"
|
||||||
*/
|
*/
|
||||||
public final class AutoWiringSpringBeanJobFactory extends SpringBeanJobFactory
|
public final class AutoWiringSpringBeanJobFactory extends SpringBeanJobFactory implements ApplicationContextAware {
|
||||||
implements ApplicationContextAware {
|
|
||||||
|
|
||||||
private transient AutowireCapableBeanFactory beanFactory;
|
private transient AutowireCapableBeanFactory beanFactory;
|
||||||
|
|
||||||
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||||
public void setApplicationContext(ApplicationContext applicationContext)
|
|
||||||
throws BeansException {
|
|
||||||
|
|
||||||
beanFactory = applicationContext.getAutowireCapableBeanFactory();
|
beanFactory = applicationContext.getAutowireCapableBeanFactory();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Object createJobInstance(final TriggerFiredBundle bundle)
|
protected Object createJobInstance(final TriggerFiredBundle bundle) throws Exception {
|
||||||
throws Exception {
|
|
||||||
|
|
||||||
final Object job = super.createJobInstance(bundle);
|
final Object job = super.createJobInstance(bundle);
|
||||||
beanFactory.autowireBean(job);
|
beanFactory.autowireBean(job);
|
||||||
|
@ -4,10 +4,12 @@
|
|||||||
package org.baeldung.web.dto;
|
package org.baeldung.web.dto;
|
||||||
|
|
||||||
public final class FooProtos {
|
public final class FooProtos {
|
||||||
private FooProtos() {}
|
private FooProtos() {
|
||||||
public static void registerAllExtensions(
|
|
||||||
com.google.protobuf.ExtensionRegistry registry) {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void registerAllExtensions(com.google.protobuf.ExtensionRegistry registry) {
|
||||||
|
}
|
||||||
|
|
||||||
public interface FooOrBuilder extends
|
public interface FooOrBuilder extends
|
||||||
// @@protoc_insertion_point(interface_extends:baeldung.Foo)
|
// @@protoc_insertion_point(interface_extends:baeldung.Foo)
|
||||||
com.google.protobuf.MessageOrBuilder {
|
com.google.protobuf.MessageOrBuilder {
|
||||||
@ -16,6 +18,7 @@ public final class FooProtos {
|
|||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
boolean hasId();
|
boolean hasId();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
@ -25,21 +28,22 @@ public final class FooProtos {
|
|||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
boolean hasName();
|
boolean hasName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
java.lang.String getName();
|
java.lang.String getName();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
com.google.protobuf.ByteString
|
com.google.protobuf.ByteString getNameBytes();
|
||||||
getNameBytes();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protobuf type {@code baeldung.Foo}
|
* Protobuf type {@code baeldung.Foo}
|
||||||
*/
|
*/
|
||||||
public static final class Foo extends
|
public static final class Foo extends com.google.protobuf.GeneratedMessage implements
|
||||||
com.google.protobuf.GeneratedMessage implements
|
|
||||||
// @@protoc_insertion_point(message_implements:baeldung.Foo)
|
// @@protoc_insertion_point(message_implements:baeldung.Foo)
|
||||||
FooOrBuilder {
|
FooOrBuilder {
|
||||||
// Use Foo.newBuilder() to construct.
|
// Use Foo.newBuilder() to construct.
|
||||||
@ -47,9 +51,13 @@ public final class FooProtos {
|
|||||||
super(builder);
|
super(builder);
|
||||||
this.unknownFields = builder.getUnknownFields();
|
this.unknownFields = builder.getUnknownFields();
|
||||||
}
|
}
|
||||||
private Foo(boolean noInit) { this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance(); }
|
|
||||||
|
private Foo(boolean noInit) {
|
||||||
|
this.unknownFields = com.google.protobuf.UnknownFieldSet.getDefaultInstance();
|
||||||
|
}
|
||||||
|
|
||||||
private static final Foo defaultInstance;
|
private static final Foo defaultInstance;
|
||||||
|
|
||||||
public static Foo getDefaultInstance() {
|
public static Foo getDefaultInstance() {
|
||||||
return defaultInstance;
|
return defaultInstance;
|
||||||
}
|
}
|
||||||
@ -59,19 +67,16 @@ public final class FooProtos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private final com.google.protobuf.UnknownFieldSet unknownFields;
|
private final com.google.protobuf.UnknownFieldSet unknownFields;
|
||||||
|
|
||||||
@java.lang.Override
|
@java.lang.Override
|
||||||
public final com.google.protobuf.UnknownFieldSet
|
public final com.google.protobuf.UnknownFieldSet getUnknownFields() {
|
||||||
getUnknownFields() {
|
|
||||||
return this.unknownFields;
|
return this.unknownFields;
|
||||||
}
|
}
|
||||||
private Foo(
|
|
||||||
com.google.protobuf.CodedInputStream input,
|
private Foo(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
|
||||||
initFields();
|
initFields();
|
||||||
int mutable_bitField0_ = 0;
|
int mutable_bitField0_ = 0;
|
||||||
com.google.protobuf.UnknownFieldSet.Builder unknownFields =
|
com.google.protobuf.UnknownFieldSet.Builder unknownFields = com.google.protobuf.UnknownFieldSet.newBuilder();
|
||||||
com.google.protobuf.UnknownFieldSet.newBuilder();
|
|
||||||
try {
|
try {
|
||||||
boolean done = false;
|
boolean done = false;
|
||||||
while (!done) {
|
while (!done) {
|
||||||
@ -81,8 +86,7 @@ public final class FooProtos {
|
|||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
default: {
|
default: {
|
||||||
if (!parseUnknownField(input, unknownFields,
|
if (!parseUnknownField(input, unknownFields, extensionRegistry, tag)) {
|
||||||
extensionRegistry, tag)) {
|
|
||||||
done = true;
|
done = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@ -103,31 +107,23 @@ public final class FooProtos {
|
|||||||
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
} catch (com.google.protobuf.InvalidProtocolBufferException e) {
|
||||||
throw e.setUnfinishedMessage(this);
|
throw e.setUnfinishedMessage(this);
|
||||||
} catch (java.io.IOException e) {
|
} catch (java.io.IOException e) {
|
||||||
throw new com.google.protobuf.InvalidProtocolBufferException(
|
throw new com.google.protobuf.InvalidProtocolBufferException(e.getMessage()).setUnfinishedMessage(this);
|
||||||
e.getMessage()).setUnfinishedMessage(this);
|
|
||||||
} finally {
|
} finally {
|
||||||
this.unknownFields = unknownFields.build();
|
this.unknownFields = unknownFields.build();
|
||||||
makeExtensionsImmutable();
|
makeExtensionsImmutable();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public static final com.google.protobuf.Descriptors.Descriptor
|
|
||||||
getDescriptor() {
|
public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
|
||||||
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() {
|
||||||
internalGetFieldAccessorTable() {
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_fieldAccessorTable.ensureFieldAccessorsInitialized(org.baeldung.web.dto.FooProtos.Foo.class, org.baeldung.web.dto.FooProtos.Foo.Builder.class);
|
||||||
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_fieldAccessorTable
|
|
||||||
.ensureFieldAccessorsInitialized(
|
|
||||||
org.baeldung.web.dto.FooProtos.Foo.class, org.baeldung.web.dto.FooProtos.Foo.Builder.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static com.google.protobuf.Parser<Foo> PARSER =
|
public static com.google.protobuf.Parser<Foo> PARSER = new com.google.protobuf.AbstractParser<Foo>() {
|
||||||
new com.google.protobuf.AbstractParser<Foo>() {
|
public Foo parsePartialFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
public Foo parsePartialFrom(
|
|
||||||
com.google.protobuf.CodedInputStream input,
|
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
|
||||||
return new Foo(input, extensionRegistry);
|
return new Foo(input, extensionRegistry);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -140,12 +136,14 @@ public final class FooProtos {
|
|||||||
private int bitField0_;
|
private int bitField0_;
|
||||||
public static final int ID_FIELD_NUMBER = 1;
|
public static final int ID_FIELD_NUMBER = 1;
|
||||||
private long id_;
|
private long id_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasId() {
|
public boolean hasId() {
|
||||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
@ -155,12 +153,14 @@ public final class FooProtos {
|
|||||||
|
|
||||||
public static final int NAME_FIELD_NUMBER = 2;
|
public static final int NAME_FIELD_NUMBER = 2;
|
||||||
private java.lang.Object name_;
|
private java.lang.Object name_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasName() {
|
public boolean hasName() {
|
||||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
@ -169,8 +169,7 @@ public final class FooProtos {
|
|||||||
if (ref instanceof java.lang.String) {
|
if (ref instanceof java.lang.String) {
|
||||||
return (java.lang.String) ref;
|
return (java.lang.String) ref;
|
||||||
} else {
|
} else {
|
||||||
com.google.protobuf.ByteString bs =
|
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
|
||||||
(com.google.protobuf.ByteString) ref;
|
|
||||||
java.lang.String s = bs.toStringUtf8();
|
java.lang.String s = bs.toStringUtf8();
|
||||||
if (bs.isValidUtf8()) {
|
if (bs.isValidUtf8()) {
|
||||||
name_ = s;
|
name_ = s;
|
||||||
@ -178,16 +177,14 @@ public final class FooProtos {
|
|||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
public com.google.protobuf.ByteString
|
public com.google.protobuf.ByteString getNameBytes() {
|
||||||
getNameBytes() {
|
|
||||||
java.lang.Object ref = name_;
|
java.lang.Object ref = name_;
|
||||||
if (ref instanceof java.lang.String) {
|
if (ref instanceof java.lang.String) {
|
||||||
com.google.protobuf.ByteString b =
|
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
|
||||||
com.google.protobuf.ByteString.copyFromUtf8(
|
|
||||||
(java.lang.String) ref);
|
|
||||||
name_ = b;
|
name_ = b;
|
||||||
return b;
|
return b;
|
||||||
} else {
|
} else {
|
||||||
@ -199,11 +196,15 @@ public final class FooProtos {
|
|||||||
id_ = 0L;
|
id_ = 0L;
|
||||||
name_ = "";
|
name_ = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
private byte memoizedIsInitialized = -1;
|
private byte memoizedIsInitialized = -1;
|
||||||
|
|
||||||
public final boolean isInitialized() {
|
public final boolean isInitialized() {
|
||||||
byte isInitialized = memoizedIsInitialized;
|
byte isInitialized = memoizedIsInitialized;
|
||||||
if (isInitialized == 1) return true;
|
if (isInitialized == 1)
|
||||||
if (isInitialized == 0) return false;
|
return true;
|
||||||
|
if (isInitialized == 0)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!hasId()) {
|
if (!hasId()) {
|
||||||
memoizedIsInitialized = 0;
|
memoizedIsInitialized = 0;
|
||||||
@ -217,8 +218,7 @@ public final class FooProtos {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
public void writeTo(com.google.protobuf.CodedOutputStream output) throws java.io.IOException {
|
||||||
throws java.io.IOException {
|
|
||||||
getSerializedSize();
|
getSerializedSize();
|
||||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||||
output.writeInt64(1, id_);
|
output.writeInt64(1, id_);
|
||||||
@ -230,18 +230,18 @@ public final class FooProtos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int memoizedSerializedSize = -1;
|
private int memoizedSerializedSize = -1;
|
||||||
|
|
||||||
public int getSerializedSize() {
|
public int getSerializedSize() {
|
||||||
int size = memoizedSerializedSize;
|
int size = memoizedSerializedSize;
|
||||||
if (size != -1) return size;
|
if (size != -1)
|
||||||
|
return size;
|
||||||
|
|
||||||
size = 0;
|
size = 0;
|
||||||
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
if (((bitField0_ & 0x00000001) == 0x00000001)) {
|
||||||
size += com.google.protobuf.CodedOutputStream
|
size += com.google.protobuf.CodedOutputStream.computeInt64Size(1, id_);
|
||||||
.computeInt64Size(1, id_);
|
|
||||||
}
|
}
|
||||||
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
if (((bitField0_ & 0x00000002) == 0x00000002)) {
|
||||||
size += com.google.protobuf.CodedOutputStream
|
size += com.google.protobuf.CodedOutputStream.computeBytesSize(2, getNameBytes());
|
||||||
.computeBytesSize(2, getNameBytes());
|
|
||||||
}
|
}
|
||||||
size += getUnknownFields().getSerializedSize();
|
size += getUnknownFields().getSerializedSize();
|
||||||
memoizedSerializedSize = size;
|
memoizedSerializedSize = size;
|
||||||
@ -249,95 +249,86 @@ public final class FooProtos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static final long serialVersionUID = 0L;
|
private static final long serialVersionUID = 0L;
|
||||||
|
|
||||||
@java.lang.Override
|
@java.lang.Override
|
||||||
protected java.lang.Object writeReplace()
|
protected java.lang.Object writeReplace() throws java.io.ObjectStreamException {
|
||||||
throws java.io.ObjectStreamException {
|
|
||||||
return super.writeReplace();
|
return super.writeReplace();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(com.google.protobuf.ByteString data) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
com.google.protobuf.ByteString data)
|
|
||||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
|
||||||
return PARSER.parseFrom(data);
|
return PARSER.parseFrom(data);
|
||||||
}
|
}
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
|
||||||
com.google.protobuf.ByteString data,
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(com.google.protobuf.ByteString data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
|
||||||
return PARSER.parseFrom(data, extensionRegistry);
|
return PARSER.parseFrom(data, extensionRegistry);
|
||||||
}
|
}
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(byte[] data)
|
|
||||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(byte[] data) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
return PARSER.parseFrom(data);
|
return PARSER.parseFrom(data);
|
||||||
}
|
}
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
|
||||||
byte[] data,
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(byte[] data, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws com.google.protobuf.InvalidProtocolBufferException {
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws com.google.protobuf.InvalidProtocolBufferException {
|
|
||||||
return PARSER.parseFrom(data, extensionRegistry);
|
return PARSER.parseFrom(data, extensionRegistry);
|
||||||
}
|
}
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(java.io.InputStream input)
|
|
||||||
throws java.io.IOException {
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(java.io.InputStream input) throws java.io.IOException {
|
||||||
return PARSER.parseFrom(input);
|
return PARSER.parseFrom(input);
|
||||||
}
|
}
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
|
||||||
java.io.InputStream input,
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws java.io.IOException {
|
|
||||||
return PARSER.parseFrom(input, extensionRegistry);
|
|
||||||
}
|
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseDelimitedFrom(java.io.InputStream input)
|
|
||||||
throws java.io.IOException {
|
|
||||||
return PARSER.parseDelimitedFrom(input);
|
|
||||||
}
|
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseDelimitedFrom(
|
|
||||||
java.io.InputStream input,
|
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws java.io.IOException {
|
|
||||||
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
|
||||||
}
|
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
|
||||||
com.google.protobuf.CodedInputStream input)
|
|
||||||
throws java.io.IOException {
|
|
||||||
return PARSER.parseFrom(input);
|
|
||||||
}
|
|
||||||
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(
|
|
||||||
com.google.protobuf.CodedInputStream input,
|
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws java.io.IOException {
|
|
||||||
return PARSER.parseFrom(input, extensionRegistry);
|
return PARSER.parseFrom(input, extensionRegistry);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Builder newBuilder() { return Builder.create(); }
|
public static org.baeldung.web.dto.FooProtos.Foo parseDelimitedFrom(java.io.InputStream input) throws java.io.IOException {
|
||||||
public Builder newBuilderForType() { return newBuilder(); }
|
return PARSER.parseDelimitedFrom(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseDelimitedFrom(java.io.InputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||||
|
return PARSER.parseDelimitedFrom(input, extensionRegistry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(com.google.protobuf.CodedInputStream input) throws java.io.IOException {
|
||||||
|
return PARSER.parseFrom(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static org.baeldung.web.dto.FooProtos.Foo parseFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||||
|
return PARSER.parseFrom(input, extensionRegistry);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Builder newBuilder() {
|
||||||
|
return Builder.create();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Builder newBuilderForType() {
|
||||||
|
return newBuilder();
|
||||||
|
}
|
||||||
|
|
||||||
public static Builder newBuilder(org.baeldung.web.dto.FooProtos.Foo prototype) {
|
public static Builder newBuilder(org.baeldung.web.dto.FooProtos.Foo prototype) {
|
||||||
return newBuilder().mergeFrom(prototype);
|
return newBuilder().mergeFrom(prototype);
|
||||||
}
|
}
|
||||||
public Builder toBuilder() { return newBuilder(this); }
|
|
||||||
|
public Builder toBuilder() {
|
||||||
|
return newBuilder(this);
|
||||||
|
}
|
||||||
|
|
||||||
@java.lang.Override
|
@java.lang.Override
|
||||||
protected Builder newBuilderForType(
|
protected Builder newBuilderForType(com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
|
||||||
Builder builder = new Builder(parent);
|
Builder builder = new Builder(parent);
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protobuf type {@code baeldung.Foo}
|
* Protobuf type {@code baeldung.Foo}
|
||||||
*/
|
*/
|
||||||
public static final class Builder extends
|
public static final class Builder extends com.google.protobuf.GeneratedMessage.Builder<Builder> implements
|
||||||
com.google.protobuf.GeneratedMessage.Builder<Builder> implements
|
|
||||||
// @@protoc_insertion_point(builder_implements:baeldung.Foo)
|
// @@protoc_insertion_point(builder_implements:baeldung.Foo)
|
||||||
org.baeldung.web.dto.FooProtos.FooOrBuilder {
|
org.baeldung.web.dto.FooProtos.FooOrBuilder {
|
||||||
public static final com.google.protobuf.Descriptors.Descriptor
|
public static final com.google.protobuf.Descriptors.Descriptor getDescriptor() {
|
||||||
getDescriptor() {
|
|
||||||
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
protected com.google.protobuf.GeneratedMessage.FieldAccessorTable internalGetFieldAccessorTable() {
|
||||||
internalGetFieldAccessorTable() {
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_fieldAccessorTable.ensureFieldAccessorsInitialized(org.baeldung.web.dto.FooProtos.Foo.class, org.baeldung.web.dto.FooProtos.Foo.Builder.class);
|
||||||
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_fieldAccessorTable
|
|
||||||
.ensureFieldAccessorsInitialized(
|
|
||||||
org.baeldung.web.dto.FooProtos.Foo.class, org.baeldung.web.dto.FooProtos.Foo.Builder.class);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Construct using org.baeldung.web.dto.FooProtos.Foo.newBuilder()
|
// Construct using org.baeldung.web.dto.FooProtos.Foo.newBuilder()
|
||||||
@ -345,15 +336,16 @@ public final class FooProtos {
|
|||||||
maybeForceBuilderInitialization();
|
maybeForceBuilderInitialization();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Builder(
|
private Builder(com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
||||||
com.google.protobuf.GeneratedMessage.BuilderParent parent) {
|
|
||||||
super(parent);
|
super(parent);
|
||||||
maybeForceBuilderInitialization();
|
maybeForceBuilderInitialization();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeForceBuilderInitialization() {
|
private void maybeForceBuilderInitialization() {
|
||||||
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
|
if (com.google.protobuf.GeneratedMessage.alwaysUseFieldBuilders) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Builder create() {
|
private static Builder create() {
|
||||||
return new Builder();
|
return new Builder();
|
||||||
}
|
}
|
||||||
@ -371,8 +363,7 @@ public final class FooProtos {
|
|||||||
return create().mergeFrom(buildPartial());
|
return create().mergeFrom(buildPartial());
|
||||||
}
|
}
|
||||||
|
|
||||||
public com.google.protobuf.Descriptors.Descriptor
|
public com.google.protobuf.Descriptors.Descriptor getDescriptorForType() {
|
||||||
getDescriptorForType() {
|
|
||||||
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
return org.baeldung.web.dto.FooProtos.internal_static_baeldung_Foo_descriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -415,7 +406,8 @@ public final class FooProtos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Builder mergeFrom(org.baeldung.web.dto.FooProtos.Foo other) {
|
public Builder mergeFrom(org.baeldung.web.dto.FooProtos.Foo other) {
|
||||||
if (other == org.baeldung.web.dto.FooProtos.Foo.getDefaultInstance()) return this;
|
if (other == org.baeldung.web.dto.FooProtos.Foo.getDefaultInstance())
|
||||||
|
return this;
|
||||||
if (other.hasId()) {
|
if (other.hasId()) {
|
||||||
setId(other.getId());
|
setId(other.getId());
|
||||||
}
|
}
|
||||||
@ -440,10 +432,7 @@ public final class FooProtos {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Builder mergeFrom(
|
public Builder mergeFrom(com.google.protobuf.CodedInputStream input, com.google.protobuf.ExtensionRegistryLite extensionRegistry) throws java.io.IOException {
|
||||||
com.google.protobuf.CodedInputStream input,
|
|
||||||
com.google.protobuf.ExtensionRegistryLite extensionRegistry)
|
|
||||||
throws java.io.IOException {
|
|
||||||
org.baeldung.web.dto.FooProtos.Foo parsedMessage = null;
|
org.baeldung.web.dto.FooProtos.Foo parsedMessage = null;
|
||||||
try {
|
try {
|
||||||
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
parsedMessage = PARSER.parsePartialFrom(input, extensionRegistry);
|
||||||
@ -457,21 +446,25 @@ public final class FooProtos {
|
|||||||
}
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private int bitField0_;
|
private int bitField0_;
|
||||||
|
|
||||||
private long id_;
|
private long id_;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasId() {
|
public boolean hasId() {
|
||||||
return ((bitField0_ & 0x00000001) == 0x00000001);
|
return ((bitField0_ & 0x00000001) == 0x00000001);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
public long getId() {
|
public long getId() {
|
||||||
return id_;
|
return id_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
@ -481,6 +474,7 @@ public final class FooProtos {
|
|||||||
onChanged();
|
onChanged();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required int64 id = 1;</code>
|
* <code>required int64 id = 1;</code>
|
||||||
*/
|
*/
|
||||||
@ -492,20 +486,21 @@ public final class FooProtos {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private java.lang.Object name_ = "";
|
private java.lang.Object name_ = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
public boolean hasName() {
|
public boolean hasName() {
|
||||||
return ((bitField0_ & 0x00000002) == 0x00000002);
|
return ((bitField0_ & 0x00000002) == 0x00000002);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
public java.lang.String getName() {
|
public java.lang.String getName() {
|
||||||
java.lang.Object ref = name_;
|
java.lang.Object ref = name_;
|
||||||
if (!(ref instanceof java.lang.String)) {
|
if (!(ref instanceof java.lang.String)) {
|
||||||
com.google.protobuf.ByteString bs =
|
com.google.protobuf.ByteString bs = (com.google.protobuf.ByteString) ref;
|
||||||
(com.google.protobuf.ByteString) ref;
|
|
||||||
java.lang.String s = bs.toStringUtf8();
|
java.lang.String s = bs.toStringUtf8();
|
||||||
if (bs.isValidUtf8()) {
|
if (bs.isValidUtf8()) {
|
||||||
name_ = s;
|
name_ = s;
|
||||||
@ -515,27 +510,25 @@ public final class FooProtos {
|
|||||||
return (java.lang.String) ref;
|
return (java.lang.String) ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
public com.google.protobuf.ByteString
|
public com.google.protobuf.ByteString getNameBytes() {
|
||||||
getNameBytes() {
|
|
||||||
java.lang.Object ref = name_;
|
java.lang.Object ref = name_;
|
||||||
if (ref instanceof String) {
|
if (ref instanceof String) {
|
||||||
com.google.protobuf.ByteString b =
|
com.google.protobuf.ByteString b = com.google.protobuf.ByteString.copyFromUtf8((java.lang.String) ref);
|
||||||
com.google.protobuf.ByteString.copyFromUtf8(
|
|
||||||
(java.lang.String) ref);
|
|
||||||
name_ = b;
|
name_ = b;
|
||||||
return b;
|
return b;
|
||||||
} else {
|
} else {
|
||||||
return (com.google.protobuf.ByteString) ref;
|
return (com.google.protobuf.ByteString) ref;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
public Builder setName(
|
public Builder setName(java.lang.String value) {
|
||||||
java.lang.String value) {
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
@ -544,6 +537,7 @@ public final class FooProtos {
|
|||||||
onChanged();
|
onChanged();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
@ -553,11 +547,11 @@ public final class FooProtos {
|
|||||||
onChanged();
|
onChanged();
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <code>required string name = 2;</code>
|
* <code>required string name = 2;</code>
|
||||||
*/
|
*/
|
||||||
public Builder setNameBytes(
|
public Builder setNameBytes(com.google.protobuf.ByteString value) {
|
||||||
com.google.protobuf.ByteString value) {
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
throw new NullPointerException();
|
throw new NullPointerException();
|
||||||
}
|
}
|
||||||
@ -578,42 +572,25 @@ public final class FooProtos {
|
|||||||
// @@protoc_insertion_point(class_scope:baeldung.Foo)
|
// @@protoc_insertion_point(class_scope:baeldung.Foo)
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final com.google.protobuf.Descriptors.Descriptor
|
private static final com.google.protobuf.Descriptors.Descriptor internal_static_baeldung_Foo_descriptor;
|
||||||
internal_static_baeldung_Foo_descriptor;
|
private static com.google.protobuf.GeneratedMessage.FieldAccessorTable internal_static_baeldung_Foo_fieldAccessorTable;
|
||||||
private static
|
|
||||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable
|
|
||||||
internal_static_baeldung_Foo_fieldAccessorTable;
|
|
||||||
|
|
||||||
public static com.google.protobuf.Descriptors.FileDescriptor
|
public static com.google.protobuf.Descriptors.FileDescriptor getDescriptor() {
|
||||||
getDescriptor() {
|
|
||||||
return descriptor;
|
return descriptor;
|
||||||
}
|
}
|
||||||
private static com.google.protobuf.Descriptors.FileDescriptor
|
|
||||||
descriptor;
|
private static com.google.protobuf.Descriptors.FileDescriptor descriptor;
|
||||||
static {
|
static {
|
||||||
java.lang.String[] descriptorData = {
|
java.lang.String[] descriptorData = { "\n\017FooProtos.proto\022\010baeldung\"\037\n\003Foo\022\n\n\002id" + "\030\001 \002(\003\022\014\n\004name\030\002 \002(\tB!\n\024org.baeldung.web" + ".dtoB\tFooProtos" };
|
||||||
"\n\017FooProtos.proto\022\010baeldung\"\037\n\003Foo\022\n\n\002id" +
|
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||||
"\030\001 \002(\003\022\014\n\004name\030\002 \002(\tB!\n\024org.baeldung.web" +
|
public com.google.protobuf.ExtensionRegistry assignDescriptors(com.google.protobuf.Descriptors.FileDescriptor root) {
|
||||||
".dtoB\tFooProtos"
|
|
||||||
};
|
|
||||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
|
||||||
new com.google.protobuf.Descriptors.FileDescriptor. InternalDescriptorAssigner() {
|
|
||||||
public com.google.protobuf.ExtensionRegistry assignDescriptors(
|
|
||||||
com.google.protobuf.Descriptors.FileDescriptor root) {
|
|
||||||
descriptor = root;
|
descriptor = root;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
com.google.protobuf.Descriptors.FileDescriptor
|
com.google.protobuf.Descriptors.FileDescriptor.internalBuildGeneratedFileFrom(descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] {}, assigner);
|
||||||
.internalBuildGeneratedFileFrom(descriptorData,
|
internal_static_baeldung_Foo_descriptor = getDescriptor().getMessageTypes().get(0);
|
||||||
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
internal_static_baeldung_Foo_fieldAccessorTable = new com.google.protobuf.GeneratedMessage.FieldAccessorTable(internal_static_baeldung_Foo_descriptor, new java.lang.String[] { "Id", "Name", });
|
||||||
}, assigner);
|
|
||||||
internal_static_baeldung_Foo_descriptor =
|
|
||||||
getDescriptor().getMessageTypes().get(0);
|
|
||||||
internal_static_baeldung_Foo_fieldAccessorTable = new
|
|
||||||
com.google.protobuf.GeneratedMessage.FieldAccessorTable(
|
|
||||||
internal_static_baeldung_Foo_descriptor,
|
|
||||||
new java.lang.String[] { "Id", "Name", });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @@protoc_insertion_point(outer_class_scope)
|
// @@protoc_insertion_point(outer_class_scope)
|
||||||
|
@ -32,13 +32,11 @@ public class ExampleControllerTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenGetRequestSentToController_thenReturnsStatusNotAcceptable() throws Exception {
|
public void whenGetRequestSentToController_thenReturnsStatusNotAcceptable() throws Exception {
|
||||||
mockMvc.perform(get("/controller"))
|
mockMvc.perform(get("/controller")).andExpect(status().isNotAcceptable());
|
||||||
.andExpect(status().isNotAcceptable());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenGetRequestSentToException_thenReturnsStatusForbidden() throws Exception {
|
public void whenGetRequestSentToException_thenReturnsStatusForbidden() throws Exception {
|
||||||
mockMvc.perform(get("/exception"))
|
mockMvc.perform(get("/exception")).andExpect(status().isForbidden());
|
||||||
.andExpect(status().isForbidden());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,9 +51,7 @@ public class MyUserDetailsService implements UserDetailsService {
|
|||||||
private User createUser(final String username, final String password, final List<SecurityRole> roles) {
|
private User createUser(final String username, final String password, final List<SecurityRole> roles) {
|
||||||
logger.info("Create user " + username);
|
logger.info("Create user " + username);
|
||||||
|
|
||||||
final List<GrantedAuthority> authorities = roles.stream()
|
final List<GrantedAuthority> authorities = roles.stream().map(role -> new SimpleGrantedAuthority(role.toString())).collect(Collectors.toList());
|
||||||
.map(role -> new SimpleGrantedAuthority(role.toString()))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
return new User(username, password, true, true, true, true, authorities);
|
return new User(username, password, true, true, true, true, authorities);
|
||||||
}
|
}
|
||||||
|
@ -37,5 +37,4 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
|||||||
// @formatter:on
|
// @formatter:on
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,15 +24,13 @@ public class SessionTimerInterceptor extends HandlerInterceptorAdapter {
|
|||||||
* Executed before actual handler is executed
|
* Executed before actual handler is executed
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler)
|
public boolean preHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler) throws Exception {
|
||||||
throws Exception {
|
|
||||||
log.info("Pre handle method - check handling start time");
|
log.info("Pre handle method - check handling start time");
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
request.setAttribute("executionTime", startTime);
|
request.setAttribute("executionTime", startTime);
|
||||||
if (UserInterceptor.isUserLogged()) {
|
if (UserInterceptor.isUserLogged()) {
|
||||||
session = request.getSession();
|
session = request.getSession();
|
||||||
log.info("Time since last request in this session: {} ms",
|
log.info("Time since last request in this session: {} ms", System.currentTimeMillis() - request.getSession().getLastAccessedTime());
|
||||||
System.currentTimeMillis() - request.getSession().getLastAccessedTime());
|
|
||||||
if (System.currentTimeMillis() - session.getLastAccessedTime() > MAX_INACTIVE_SESSION_TIME) {
|
if (System.currentTimeMillis() - session.getLastAccessedTime() > MAX_INACTIVE_SESSION_TIME) {
|
||||||
log.warn("Logging out, due to inactive session");
|
log.warn("Logging out, due to inactive session");
|
||||||
SecurityContextHolder.clearContext();
|
SecurityContextHolder.clearContext();
|
||||||
@ -47,8 +45,7 @@ public class SessionTimerInterceptor extends HandlerInterceptorAdapter {
|
|||||||
* Executed before after handler is executed
|
* Executed before after handler is executed
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler,
|
public void postHandle(final HttpServletRequest request, final HttpServletResponse response, final Object handler, final ModelAndView model) throws Exception {
|
||||||
final ModelAndView model) throws Exception {
|
|
||||||
log.info("Post handle method - check execution time of handling");
|
log.info("Post handle method - check execution time of handling");
|
||||||
long startTime = (Long) request.getAttribute("executionTime");
|
long startTime = (Long) request.getAttribute("executionTime");
|
||||||
log.info("Execution time for handling the request was: {} ms", System.currentTimeMillis() - startTime);
|
log.info("Execution time for handling the request was: {} ms", System.currentTimeMillis() - startTime);
|
||||||
|
@ -31,8 +31,7 @@ public class UserInterceptor extends HandlerInterceptorAdapter {
|
|||||||
* Executed before after handler is executed. If view is a redirect view, we don't need to execute postHandle
|
* Executed before after handler is executed. If view is a redirect view, we don't need to execute postHandle
|
||||||
**/
|
**/
|
||||||
@Override
|
@Override
|
||||||
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object, ModelAndView model)
|
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object object, ModelAndView model) throws Exception {
|
||||||
throws Exception {
|
|
||||||
if (model != null && !isRedirectView(model)) {
|
if (model != null && !isRedirectView(model)) {
|
||||||
if (isUserLogged()) {
|
if (isUserLogged()) {
|
||||||
addToModelUserDetails(model);
|
addToModelUserDetails(model);
|
||||||
|
@ -47,8 +47,7 @@ public class SessionTimerInterceptorTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInterceptors() throws Exception {
|
public void testInterceptors() throws Exception {
|
||||||
HttpSession session = mockMvc.perform(get("/auth/admin")).andExpect(status().is2xxSuccessful()).andReturn()
|
HttpSession session = mockMvc.perform(get("/auth/admin")).andExpect(status().is2xxSuccessful()).andReturn().getRequest().getSession();
|
||||||
.getRequest().getSession();
|
|
||||||
Thread.sleep(51000);
|
Thread.sleep(51000);
|
||||||
mockMvc.perform(get("/auth/admin").session((MockHttpSession) session)).andExpect(status().is2xxSuccessful());
|
mockMvc.perform(get("/auth/admin").session((MockHttpSession) session)).andExpect(status().is2xxSuccessful());
|
||||||
}
|
}
|
||||||
|
@ -46,8 +46,7 @@ public class UserInterceptorTest {
|
|||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testInterceptors() throws Exception {
|
public void testInterceptors() throws Exception {
|
||||||
mockMvc.perform(get("/auth/admin"))
|
mockMvc.perform(get("/auth/admin")).andExpect(status().is2xxSuccessful());
|
||||||
.andExpect(status().is2xxSuccessful());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user