Skip to content

Commit

Permalink
Added a simple integration test.
Browse files Browse the repository at this point in the history
  • Loading branch information
bardia-p committed Nov 11, 2023
1 parent 846547c commit dda450d
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 71 deletions.
65 changes: 0 additions & 65 deletions src/test/java/com/opinionowl/opinionowl/IntegrationTest.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.opinionowl.opinionowl.IntegrationTests;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;

import java.util.List;

import static org.hamcrest.Matchers.containsString;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@SpringBootTest
@AutoConfigureMockMvc
public class CreateSurveyIntegrationTest {
@Autowired
private MockMvc mockMvc;

/**
* Test method for POSTing a survey and doing a GET after
*/
@Test
public void testCreateAndRetrieveSurvey() throws Exception {
String postData = "{\"radioQuestions\":{\"Test2\":[\"a\",\"b\"]},\"numericRanges\":{\"Test3\":[0,11]},\"title\":\"Form Title\",\"textQuestions\":[\"Test1\"]}";

// Create a survey using the POST request.
this.mockMvc.perform(post("/api/v1/createSurvey")
.contentType(MediaType.APPLICATION_JSON).content(postData))
.andExpect(status().isOk());

// Expect the survey to show up on the home page.
this.mockMvc.perform(get("/")).andExpect(status().isOk())
.andExpect(content().string(containsString("Form Title")));

}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.opinionowl.opinionowl;
package com.opinionowl.opinionowl.IntegrationTests;

import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.opinionowl.opinionowl;
package com.opinionowl.opinionowl.ModelTests;
import com.opinionowl.opinionowl.models.*;
import com.opinionowl.opinionowl.repos.*;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.opinionowl.opinionowl;
package com.opinionowl.opinionowl.ModelTests;
import com.opinionowl.opinionowl.models.*;
import com.opinionowl.opinionowl.repos.*;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.opinionowl.opinionowl;
package com.opinionowl.opinionowl.ModelTests;
import com.opinionowl.opinionowl.models.*;
import com.opinionowl.opinionowl.repos.*;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.opinionowl.opinionowl;
package com.opinionowl.opinionowl.ModelTests;
import com.opinionowl.opinionowl.models.*;
import com.opinionowl.opinionowl.repos.*;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.opinionowl.opinionowl;
package com.opinionowl.opinionowl.ModelTests;
import com.opinionowl.opinionowl.models.*;
import com.opinionowl.opinionowl.repos.*;
import org.junit.jupiter.api.Test;
Expand Down

0 comments on commit dda450d

Please sign in to comment.