PAN-11 fixed all integration tests
This commit is contained in:
@@ -36,7 +36,7 @@ version int default 1
|
|||||||
);
|
);
|
||||||
create table proofs
|
create table proofs
|
||||||
(
|
(
|
||||||
id int not null auto_increment primary key unique,
|
id int not null auto_increment,
|
||||||
theorem_name varchar(512) not null,
|
theorem_name varchar(512) not null,
|
||||||
proof varchar(4096) not null,
|
proof varchar(4096) not null,
|
||||||
branch varchar(512) not null,
|
branch varchar(512) not null,
|
||||||
@@ -45,5 +45,6 @@ create table proofs
|
|||||||
referenced_theorems json,
|
referenced_theorems json,
|
||||||
date_added date,
|
date_added date,
|
||||||
last_updated date,
|
last_updated date,
|
||||||
version int default 1
|
version int default 1,
|
||||||
|
primary key (id)
|
||||||
);
|
);
|
||||||
@@ -27,6 +27,6 @@ dependencies {
|
|||||||
compile fileTree(dir: 'lib', include: '**/*.jar')
|
compile fileTree(dir: 'lib', include: '**/*.jar')
|
||||||
|
|
||||||
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
testCompile "org.springframework:spring-test:5.0.9.RELEASE"
|
||||||
testCompile group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: '2.1.2.RELEASE'
|
|
||||||
testCompile group: 'junit', name: 'junit', version: '4.12'
|
testCompile group: 'junit', name: 'junit', version: '4.12'
|
||||||
|
testCompile group: 'org.springframework', name: 'spring-test', version: '5.1.5.RELEASE'
|
||||||
}
|
}
|
||||||
|
|||||||
+85
@@ -0,0 +1,85 @@
|
|||||||
|
package edu.msudenver.tsp.services;
|
||||||
|
|
||||||
|
import edu.msudenver.tsp.services.dto.Definition;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
|
import org.springframework.test.context.TestPropertySource;
|
||||||
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.equalTo;
|
||||||
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
|
@ContextConfiguration(classes = ServicesTestConfig.class)
|
||||||
|
@TestPropertySource(locations = "classpath:test.properties")
|
||||||
|
public class DefinitionServiceIntegrationTest {
|
||||||
|
@Autowired private DefinitionService definitionService;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCRUD() {
|
||||||
|
final Definition testDefinition = createDefinition();
|
||||||
|
final Optional<Definition> createdDefinition = definitionService.createDefinition(testDefinition);
|
||||||
|
|
||||||
|
assertTrue(createdDefinition.isPresent());
|
||||||
|
assertNotEquals(0, createdDefinition.get().getId());
|
||||||
|
assertThat(createdDefinition.get().getVersion(), is(0));
|
||||||
|
assertThat(createdDefinition.get().getName(), is("Test Name"));
|
||||||
|
assertNotNull(createdDefinition.get().getDefinition());
|
||||||
|
assertThat(createdDefinition.get().getDefinition().size(), is(1));
|
||||||
|
assertThat(createdDefinition.get().getDefinition().get(0), is("Test definition 1"));
|
||||||
|
assertNotNull(createdDefinition.get().getNotation());
|
||||||
|
assertThat(createdDefinition.get().getNotation().size(), is(1));
|
||||||
|
assertThat(createdDefinition.get().getNotation().get(0), is("\\testLaTeX"));
|
||||||
|
|
||||||
|
final Optional<Definition> definitionFoundById = definitionService.findById(createdDefinition.get().getId());
|
||||||
|
|
||||||
|
assertThat(definitionFoundById.get(), is(equalTo(createdDefinition.get())));
|
||||||
|
|
||||||
|
final Definition definitionUpdate = new Definition();
|
||||||
|
definitionUpdate.setId(createdDefinition.get().getId());
|
||||||
|
definitionUpdate.setName("Test Update");
|
||||||
|
|
||||||
|
final Optional<Definition> updatedDefinition = definitionService.updateDefinition(definitionUpdate);
|
||||||
|
|
||||||
|
assertTrue(updatedDefinition.isPresent());
|
||||||
|
assertNotEquals(0, updatedDefinition.get().getId());
|
||||||
|
assertThat(updatedDefinition.get().getVersion(), is(1));
|
||||||
|
assertThat(updatedDefinition.get().getName(), is("Test Update"));
|
||||||
|
assertNotNull(updatedDefinition.get().getDefinition());
|
||||||
|
assertThat(updatedDefinition.get().getDefinition().size(), is(1));
|
||||||
|
assertThat(updatedDefinition.get().getDefinition().get(0), is("Test definition 1"));
|
||||||
|
assertNotNull(updatedDefinition.get().getNotation());
|
||||||
|
assertThat(updatedDefinition.get().getNotation().size(), is(1));
|
||||||
|
assertThat(updatedDefinition.get().getNotation().get(0), is("\\testLaTeX"));
|
||||||
|
|
||||||
|
final boolean deletionWasSuccessful = definitionService.deleteDefinition(updatedDefinition.get());
|
||||||
|
|
||||||
|
assertThat(deletionWasSuccessful, is(true));
|
||||||
|
|
||||||
|
final Optional<Definition> deletedDefinitionFoundById = definitionService.findById(createdDefinition.get().getId());
|
||||||
|
|
||||||
|
assertFalse(deletedDefinitionFoundById.isPresent());
|
||||||
|
}
|
||||||
|
|
||||||
|
private Definition createDefinition() {
|
||||||
|
final List<String> definitionList = new ArrayList<>();
|
||||||
|
definitionList.add("Test definition 1");
|
||||||
|
|
||||||
|
final List<String> notationList = new ArrayList<>();
|
||||||
|
notationList.add("\\testLaTeX");
|
||||||
|
|
||||||
|
final Definition definition = new Definition();
|
||||||
|
definition.setName("Test Name");
|
||||||
|
definition.setDefinition(definitionList);
|
||||||
|
definition.setNotation(notationList);
|
||||||
|
|
||||||
|
return definition;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -62,7 +62,7 @@ public class DefinitionService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final TypeToken<Definition> typeToken = new TypeToken<Definition>(){};
|
final TypeToken<Definition> typeToken = new TypeToken<Definition>(){};
|
||||||
final Optional<Definition> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "/" + id,
|
final Optional<Definition> persistenceApiResponse = restService.get(persistenceApiBaseUrl + "definitions/" + id,
|
||||||
typeToken, connectionTimeoutMilliseconds, socketTimeoutMilliseconds, null);
|
typeToken, connectionTimeoutMilliseconds, socketTimeoutMilliseconds, null);
|
||||||
|
|
||||||
if (persistenceApiResponse.isPresent()) {
|
if (persistenceApiResponse.isPresent()) {
|
||||||
@@ -128,7 +128,7 @@ public class DefinitionService {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
final TypeToken<Definition> typeToken = new TypeToken<Definition>(){};
|
final TypeToken<Definition> typeToken = new TypeToken<Definition>(){};
|
||||||
final Optional<Definition> persistenceApiResponse = restService.patch(persistenceApiBaseUrl + "/" + definition.getId(),
|
final Optional<Definition> persistenceApiResponse = restService.patch(persistenceApiBaseUrl + "definitions/" + definition.getId(),
|
||||||
new GsonBuilder().create().toJson(definition),
|
new GsonBuilder().create().toJson(definition),
|
||||||
typeToken,
|
typeToken,
|
||||||
connectionTimeoutMilliseconds,
|
connectionTimeoutMilliseconds,
|
||||||
@@ -164,7 +164,7 @@ public class DefinitionService {
|
|||||||
final Instant start = Instant.now();
|
final Instant start = Instant.now();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final boolean deleteIsSuccessful = restService.delete(persistenceApiBaseUrl + "/" + definition.getId(),
|
final boolean deleteIsSuccessful = restService.delete(persistenceApiBaseUrl + "definitions/" + definition.getId(),
|
||||||
connectionTimeoutMilliseconds,
|
connectionTimeoutMilliseconds,
|
||||||
socketTimeoutMilliseconds,
|
socketTimeoutMilliseconds,
|
||||||
HttpStatus.NO_CONTENT);
|
HttpStatus.NO_CONTENT);
|
||||||
|
|||||||
@@ -13,8 +13,8 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static junit.framework.TestCase.assertTrue;
|
import static junit.framework.TestCase.assertTrue;
|
||||||
import static org.hamcrest.Matchers.equalTo;
|
import static org.hamcrest.CoreMatchers.is;
|
||||||
import static org.hamcrest.Matchers.is;
|
import static org.hamcrest.core.IsEqual.equalTo;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
import static org.mockito.Matchers.*;
|
import static org.mockito.Matchers.*;
|
||||||
import static org.mockito.Mockito.*;
|
import static org.mockito.Mockito.*;
|
||||||
|
|||||||
Reference in New Issue
Block a user