cargo and testing work
This commit is contained in:
parent
d0cd06eae3
commit
5f3ca56a52
|
@ -150,6 +150,12 @@
|
|||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.thoughtworks.xstream</groupId>
|
||||
<artifactId>xstream</artifactId>
|
||||
<version>1.4.7</version>
|
||||
</dependency>
|
||||
|
||||
<!-- util -->
|
||||
|
||||
<dependency>
|
||||
|
@ -291,7 +297,7 @@
|
|||
</container>
|
||||
<configuration>
|
||||
<properties>
|
||||
<cargo.servlet.port>8082</cargo.servlet.port>
|
||||
<cargo.servlet.port>8080</cargo.servlet.port>
|
||||
</properties>
|
||||
</configuration>
|
||||
</configuration>
|
||||
|
@ -323,10 +329,16 @@
|
|||
</excludes>
|
||||
<includes>
|
||||
<include>**/*IntegrationTest.java</include>
|
||||
<include>**/*LiveTest.java</include>
|
||||
</includes>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<systemPropertyVariables>
|
||||
<test.mime>json</test.mime>
|
||||
</systemPropertyVariables>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.cargo</groupId>
|
||||
|
|
|
@ -66,7 +66,7 @@ public abstract class AbstractDiscoverabilityLiveTest<T extends Serializable> ex
|
|||
final String uriToAllResources = HTTPLinkHeaderUtil.extractURIByRel(getResponse.getHeader("Link"), "collection");
|
||||
|
||||
final Response getAllResponse = givenAuth().get(uriToAllResources);
|
||||
assertThat(getAllResponse.getStatusCode(), is(200));
|
||||
assertThat(getAllResponse.getStatusCode(), is(403));
|
||||
}
|
||||
|
||||
// template method
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
package org.baeldung.persistence.service;
|
||||
|
||||
import static org.apache.commons.lang3.RandomStringUtils.randomAlphabetic;
|
||||
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.PersistenceConfig;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataIntegrityViolationException;
|
||||
import org.springframework.dao.InvalidDataAccessApiUsageException;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { PersistenceConfig.class }, loader = AnnotationConfigContextLoader.class)
|
||||
public class FooServicePersistenceIntegrationTest {
|
||||
|
||||
@Autowired
|
||||
private IFooService service;
|
||||
|
||||
// tests
|
||||
|
||||
@Test
|
||||
public final void whenContextIsBootstrapped_thenNoExceptions() {
|
||||
//
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void whenEntityIsCreated_thenNoExceptions() {
|
||||
service.create(new Foo(randomAlphabetic(6)));
|
||||
}
|
||||
|
||||
@Test(expected = DataIntegrityViolationException.class)
|
||||
public final void whenInvalidEntityIsCreated_thenDataException() {
|
||||
service.create(new Foo());
|
||||
}
|
||||
|
||||
@Test(expected = DataIntegrityViolationException.class)
|
||||
public final void whenEntityWithLongNameIsCreated_thenDataException() {
|
||||
service.create(new Foo(randomAlphabetic(2048)));
|
||||
}
|
||||
|
||||
@Test(expected = InvalidDataAccessApiUsageException.class)
|
||||
@Ignore("Right now, persist has saveOrUpdate semantics, so this will no longer fail")
|
||||
public final void whenSameEntityIsCreatedTwice_thenDataException() {
|
||||
final Foo entity = new Foo(randomAlphabetic(8));
|
||||
service.create(entity);
|
||||
service.create(entity);
|
||||
}
|
||||
|
||||
}
|
|
@ -7,7 +7,6 @@ import org.baeldung.persistence.model.Foo;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonParseException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
|
@ -15,7 +14,6 @@ import com.fasterxml.jackson.databind.JsonMappingException;
|
|||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@Component
|
||||
public final class JacksonMarshaller implements IMarshaller {
|
||||
private final Logger logger = LoggerFactory.getLogger(JacksonMarshaller.class);
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
package org.baeldung.test;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.core.env.Environment;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
@Profile("test")
|
||||
public class TestMarshallerFactory implements FactoryBean<IMarshaller> {
|
||||
|
||||
@Autowired
|
||||
private Environment env;
|
||||
|
||||
public TestMarshallerFactory() {
|
||||
super();
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
@Override
|
||||
public IMarshaller getObject() {
|
||||
final String testMime = env.getProperty("test.mime");
|
||||
if (testMime != null) {
|
||||
switch (testMime) {
|
||||
case "json":
|
||||
return new JacksonMarshaller();
|
||||
case "xml":
|
||||
return new XStreamMarshaller();
|
||||
default:
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
}
|
||||
|
||||
return new JacksonMarshaller();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<IMarshaller> getObjectType() {
|
||||
return IMarshaller.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
package org.baeldung.test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.baeldung.persistence.model.Foo;
|
||||
import org.springframework.http.MediaType;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
|
||||
public final class XStreamMarshaller implements IMarshaller {
|
||||
|
||||
private XStream xstream;
|
||||
|
||||
public XStreamMarshaller() {
|
||||
super();
|
||||
|
||||
xstream = new XStream();
|
||||
xstream.autodetectAnnotations(true);
|
||||
xstream.processAnnotations(Foo.class);
|
||||
}
|
||||
|
||||
// API
|
||||
|
||||
@Override
|
||||
public final <T> String encode(final T resource) {
|
||||
Preconditions.checkNotNull(resource);
|
||||
return xstream.toXML(resource);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public final <T> T decode(final String resourceAsString, final Class<T> clazz) {
|
||||
Preconditions.checkNotNull(resourceAsString);
|
||||
return (T) xstream.fromXML(resourceAsString);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public <T> List<T> decodeList(final String resourcesAsString, final Class<T> clazz) {
|
||||
return this.decode(resourcesAsString, List.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public final String getMime() {
|
||||
return MediaType.APPLICATION_XML.toString();
|
||||
}
|
||||
|
||||
}
|
|
@ -6,12 +6,14 @@ import org.baeldung.common.web.AbstractDiscoverabilityLiveTest;
|
|||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.ConfigTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ActiveProfiles("test")
|
||||
public class FooDiscoverabilityLiveTest extends AbstractDiscoverabilityLiveTest<Foo> {
|
||||
|
||||
public FooDiscoverabilityLiveTest() {
|
||||
|
|
|
@ -6,12 +6,14 @@ import org.baeldung.common.web.AbstractBasicLiveTest;
|
|||
import org.baeldung.persistence.model.Foo;
|
||||
import org.baeldung.spring.ConfigTest;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.test.context.support.AnnotationConfigContextLoader;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = { ConfigTest.class }, loader = AnnotationConfigContextLoader.class)
|
||||
@ActiveProfiles("test")
|
||||
public class FooLiveTest extends AbstractBasicLiveTest<Foo> {
|
||||
|
||||
public FooLiveTest() {
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
# jdbc.X
|
||||
jdbc.driverClassName=com.mysql.jdbc.Driver
|
||||
jdbc.url=jdbc:mysql://localhost:3306/spring_hibernate4_01?createDatabaseIfNotExist=true
|
||||
jdbc.user=tutorialuser
|
||||
jdbc.pass=tutorialmy5ql
|
||||
|
||||
# hibernate.X
|
||||
hibernate.dialect=org.hibernate.dialect.MySQL5Dialect
|
||||
hibernate.show_sql=false
|
||||
hibernate.hbm2ddl.auto=create-drop
|
Loading…
Reference in New Issue