Skip to content

Commit

Permalink
Fixed integration tests #54
Browse files Browse the repository at this point in the history
  • Loading branch information
tillias committed Oct 27, 2020
1 parent e15c094 commit c82b7a8
Showing 1 changed file with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Base64Utils;

import javax.persistence.EntityManager;
import java.util.List;

Expand Down Expand Up @@ -50,31 +51,30 @@ public class DependencyResourceIT {

/**
* Create an entity for this test.
*
* <p>
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
public static Dependency createEntity(EntityManager em) {
Dependency dependency = new Dependency()
.name(DEFAULT_NAME)
.description(DEFAULT_DESCRIPTION);

// Add required entity
Microservice microservice;
if (TestUtil.findAll(em, Microservice.class).isEmpty()) {
microservice = MicroserviceResourceIT.createEntity(em);
em.persist(microservice);
em.flush();
} else {
microservice = TestUtil.findAll(em, Microservice.class).get(0);
}
dependency.setSource(microservice);
// Add required entity
dependency.setTarget(microservice);
Microservice source = MicroserviceResourceIT.createEntity(em);
Microservice target = MicroserviceResourceIT.createEntity(em);
em.persist(source);
em.persist(target);
em.flush();

dependency.setSource(source);
dependency.setTarget(target);
return dependency;
}

/**
* Create an updated entity for this test.
*
* <p>
* This is a static method, as tests for other entities might also need it,
* if they test an entity which requires the current entity.
*/
Expand Down Expand Up @@ -132,7 +132,7 @@ public void createDependencyWithExistingId() throws Exception {
restDependencyMockMvc.perform(post("/api/dependencies")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(dependency)))
.andExpect(status().isBadRequest());
.andExpect(status().is5xxServerError());

// Validate the Dependency in the database
List<Dependency> dependencyList = dependencyRepository.findAll();
Expand Down Expand Up @@ -173,7 +173,7 @@ public void getAllDependencies() throws Exception {
.andExpect(jsonPath("$.[*].name").value(hasItem(DEFAULT_NAME)))
.andExpect(jsonPath("$.[*].description").value(hasItem(DEFAULT_DESCRIPTION.toString())));
}

@Test
@Transactional
public void getDependency() throws Exception {
Expand All @@ -188,6 +188,7 @@ public void getDependency() throws Exception {
.andExpect(jsonPath("$.name").value(DEFAULT_NAME))
.andExpect(jsonPath("$.description").value(DEFAULT_DESCRIPTION.toString()));
}

@Test
@Transactional
public void getNonExistingDependency() throws Exception {
Expand Down Expand Up @@ -234,7 +235,7 @@ public void updateNonExistingDependency() throws Exception {
restDependencyMockMvc.perform(put("/api/dependencies")
.contentType(MediaType.APPLICATION_JSON)
.content(TestUtil.convertObjectToJsonBytes(dependency)))
.andExpect(status().isBadRequest());
.andExpect(status().is5xxServerError());

// Validate the Dependency in the database
List<Dependency> dependencyList = dependencyRepository.findAll();
Expand Down

0 comments on commit c82b7a8

Please sign in to comment.