Skip to content

Commit

Permalink
[AAE-16206] test changes because csrf is on
Browse files Browse the repository at this point in the history
  • Loading branch information
wojciech-piotrowiak committed Aug 31, 2023
1 parent d44a04b commit 57b33e2
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -65,11 +67,14 @@ public class ConnectorValidationControllerIT {
@MockBean
private SecurityManager securityManager;

private MockMvc mockMvc;

@BeforeEach
public void setUp() {
webAppContextSetup(context);
when(securityManager.getAuthenticatedUserId()).thenReturn("modeler");
connectorModel = modelRepository.createModel(connectorModel("connector-name"));
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}

@AfterEach
Expand All @@ -80,6 +85,7 @@ public void cleanUp() {
@Test
public void should_returnStatusNoContent_when_validatingSimpleConnector() throws IOException {
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -98,6 +104,7 @@ public void should_returnStatusNoContent_when_validatingSimpleConnector() throws
@Test
public void should_returnStatusNoContent_when_validatingConnectorTextContentType() throws IOException {
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -116,6 +123,7 @@ public void should_returnStatusNoContent_when_validatingConnectorTextContentType
@Test
public void should_returnStatusNoContent_when_validatingConnectorWithEvents() throws IOException {
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -135,6 +143,7 @@ public void should_returnStatusNoContent_when_validatingConnectorWithEvents() th
public void should_throwSemanticValidationException_when_validatingInvalidSimpleConnector() throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand Down Expand Up @@ -162,6 +171,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidSimple
public void should_throwSyntacticValidationException_when_validatingJsonInvalidConnector() throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -186,6 +196,7 @@ public void should_throwSyntacticValidationException_when_validatingInvalidConne
throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -210,6 +221,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidConnec
throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -234,6 +246,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidConnec
public void should_throwSemanticValidationException_when_validatingInvalidConnectorNameEmpty() throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -259,6 +272,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidConnec
throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -281,6 +295,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidConnec
throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -301,6 +316,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidConnec
public void should_returnStatusNoContent_when_validatingConnectorWithCustomTypesInEventsAndActions()
throws IOException {
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -319,6 +335,7 @@ public void should_returnStatusNoContent_when_validatingConnectorWithCustomTypes
@Test
public void should_returnStatusNoContent_when_validatingConnectorWithErrors() throws IOException {
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -339,6 +356,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidConnec
throws IOException {
assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand All @@ -359,6 +377,7 @@ public void should_throwSemanticValidationException_when_validatingInvalidConnec
@Test
public void should_returnStatusNoContent_when_validatingConnectorEventWithModel() throws IOException {
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

Expand Down Expand Up @@ -89,13 +91,16 @@ public class GenericJsonModelTypeValidationControllerIT {

private Model genericJsonModel;

private MockMvc mockMvc;

@BeforeEach
public void setUp() {
webAppContextSetup(context);
when(securityManager.getAuthenticatedUserId()).thenReturn("modeler");

genericJsonModel =
modelRepository.createModel(new ModelEntity(GENERIC_MODEL_NAME, genericJsonModelType.getName()));
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}

@AfterEach
Expand Down Expand Up @@ -131,6 +136,7 @@ public void should_callGenericJsonContentValidatorAndNotCallGenericJsonExtension
byte[] fileContent = resourceAsByteArray("generic/model-simple.json");

given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model.json", fileContent, "application/json")
Expand All @@ -157,6 +163,7 @@ public void should_callGenericJsonContentValidatorAndNotCallGenericJsonExtension
byte[] fileContent = resourceAsByteArray("generic/model-simple.json");

given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model.json", fileContent, "text/plain")
Expand Down Expand Up @@ -186,6 +193,7 @@ public void should_throwExceptionAndCallGenericJsonContentValidatorAndNotCallGen

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "invalid-simple-model.json", fileContent, "application/json")
Expand Down Expand Up @@ -214,6 +222,7 @@ public void should_notCallGenericJsonContentValidatorAndCallGenericJsonExtension
byte[] fileContent = resourceAsByteArray("generic/model-simple-valid-extensions.json");

given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand All @@ -238,6 +247,7 @@ public void should_throwSemanticValidationException_when_validatingModelInvalidE

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand All @@ -264,6 +274,7 @@ public void should_throwSemanticValidationException_when_validatingModelInvalidN

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "model-simple-invalid-name-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -291,6 +302,7 @@ public void should_throwSemanticValidationException_when_validatingModelMismatch

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "model-simple-mismatch-name-extensions.json", fileContent, "application/json")
Expand All @@ -317,6 +329,7 @@ public void should_throwSemanticValidationException_when_validatingModelLongName

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "model-simple-long-name-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -347,6 +360,7 @@ public void should_throwSemanticValidationException_when_validatingModelEmptyNam

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "model-simple-empty-name-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -376,6 +390,7 @@ public void should_throwSyntacticValidationException_when_validatingInvalidJsonE

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -404,6 +419,7 @@ public void should_throwSemanticValidationException_when_validatingModelInvalidT

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -432,6 +448,7 @@ public void should_throwException_when_validatingModelInvalidSemanticExtensions(

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -472,6 +489,7 @@ public void should_throwExceptionAndCallGenericJsonContentUsageValidatorA_when_v

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "invalid-simple-model.json", fileContent, "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.context.WebApplicationContext;

Expand Down Expand Up @@ -83,11 +85,14 @@ public class GenericNonJsonModelTypeValidationControllerIT {

private Model genericNonJsonModel;

private MockMvc mockMvc;

@BeforeEach
public void setUp() {
webAppContextSetup(context);
genericNonJsonModel =
modelRepository.createModel(new ModelEntity(GENERIC_MODEL_NAME, genericNonJsonModelType.getName()));
mockMvc = MockMvcBuilders.webAppContextSetup(context).build();
}

private void validateInvalidContent() {
Expand Down Expand Up @@ -117,6 +122,7 @@ public void testValidateModelContent() throws IOException {
byte[] fileContent = resourceAsByteArray("generic/model-simple.bin");

given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model.bin", fileContent, APPLICATION_OCTET_STREAM_VALUE)
Expand All @@ -143,6 +149,7 @@ public void should_callGenericNonJsonContentValidatorAndNotCallGenericNonJsonExt
byte[] fileContent = resourceAsByteArray("generic/model-simple.bin");

given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model.bin", fileContent, "text/plain")
Expand All @@ -169,6 +176,7 @@ public void should_callGenericNonJsonContentValidatorAndNotCallGnericNonJsonExte
byte[] fileContent = resourceAsByteArray("generic/model-simple.json");

given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model.json", fileContent, "application/json")
Expand Down Expand Up @@ -198,6 +206,7 @@ public void should_throwExceptionAndCallGenericNonJsonContentValidatorAndNotCall

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "invalid-simple-model.json", fileContent, APPLICATION_OCTET_STREAM_VALUE)
Expand Down Expand Up @@ -226,6 +235,7 @@ public void should_notCallGenericNonJsonContentValidatorAndCallGenericNonJsonExt
byte[] fileContent = resourceAsByteArray("generic/model-simple-valid-extensions.json");

given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand All @@ -250,6 +260,7 @@ public void should_throwSemanticValidationException_when_validatingModelInvalidE

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand All @@ -276,6 +287,7 @@ public void should_throwSyntacticValidationException_when_validatingInvalidJsonE

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -304,6 +316,7 @@ public void should_throwSemanticValidationException_when_validatingModelInvalidT

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand Down Expand Up @@ -332,6 +345,7 @@ public void should_throwException_when_validatingModelInvalidSemanticExtensions(

assertThatResponse(
given()
.mockMvc(mockMvc)
.log()
.everything(true)
.multiPart("file", "simple-model-extensions.json", fileContent, "application/json")
Expand Down

0 comments on commit 57b33e2

Please sign in to comment.