Search in sources :

Example 11 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project mimock by neel1996.

the class MockManagementControllerTest method shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForHttpMethodInRequest_ReturnsValidationErrors.

@ParameterizedTest
@NullSource
@EmptySource
void shouldReturnHttpBadRequest_CreateMockApi_WithInvalidParametersForHttpMethodInRequest_ReturnsValidationErrors(String testData) throws Exception {
    // Arrange
    MockMultipartFile file = getMockMultipartFile();
    MockRequest mockRequest = createMockRequestWithFile(file);
    // Modify the MockRequest.HttpMethod to check
    mockRequest.setHttpMethod(testData);
    String route = UrlConfig.MOCKS_PATH;
    // Act and Assert
    mockMvc.perform(multipart(route).file(file).param("name", mockRequest.getName()).param("route", mockRequest.getRoute()).param("httpMethod", mockRequest.getHttpMethod()).param("responseContentType", mockRequest.getResponseContentType()).param("statusCode", String.valueOf(mockRequest.getStatusCode())).param("expectedTextResponse", mockRequest.getExpectedTextResponse()).param("description", mockRequest.getDescription())).andExpect(status().isBadRequest()).andExpect(response -> assertNotNull(response.getResolvedException())).andExpect(response -> assertTrue(response.getResolvedException().getMessage().contains("HttpMethod is required"))).andReturn();
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) Status(com.arbindo.mimock.manage.mimocks.models.v1.Status) MockRequest(com.arbindo.mimock.manage.mimocks.models.v1.MockRequest) UserDetailsService(org.springframework.security.core.userdetails.UserDetailsService) Autowired(org.springframework.beans.factory.annotation.Autowired) DatabaseStartupValidator(org.springframework.jdbc.support.DatabaseStartupValidator) ArrayList(java.util.ArrayList) MockMvc(org.springframework.test.web.servlet.MockMvc) DataSourceAutoConfiguration(org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration) DefaultHttpInterceptor(com.arbindo.mimock.interceptor.DefaultHttpInterceptor) EmptySource(org.junit.jupiter.params.provider.EmptySource) MvcResult(org.springframework.test.web.servlet.MvcResult) DataSource(javax.sql.DataSource) SecurityAutoConfiguration(org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration) Pageable(org.springframework.data.domain.Pageable) JsonMapper.convertObjectToJsonString(com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString) MockBean(org.springframework.boot.test.mock.mockito.MockBean) GenericResponseWrapper(com.arbindo.mimock.manage.mimocks.models.v1.GenericResponseWrapper) PrintWriter(java.io.PrintWriter) MocksGenerator(com.arbindo.mimock.helpers.entities.MocksGenerator) JpaRepositoriesAutoConfiguration(org.springframework.boot.autoconfigure.data.jpa.JpaRepositoriesAutoConfiguration) JwtRequestFilter(com.arbindo.mimock.security.JwtRequestFilter) EnableAutoConfiguration(org.springframework.boot.autoconfigure.EnableAutoConfiguration) IOException(java.io.IOException) UUID(java.util.UUID) MockMvcResultMatchers(org.springframework.test.web.servlet.result.MockMvcResultMatchers) Page(org.springframework.data.domain.Page) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) RandomDataGenerator.generateRandomAlphabeticString(com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString) ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.v1.ProcessedMockRequest) Test(org.junit.jupiter.api.Test) HttpStatus(org.springframework.http.HttpStatus) Mockito(org.mockito.Mockito) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) List(java.util.List) UrlConfig(com.arbindo.mimock.constants.UrlConfig) AutoConfigureMockMvc(org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest) MockMultipartHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockMultipartHttpServletRequestBuilder) Assertions(org.junit.jupiter.api.Assertions) UserDetailsServiceAutoConfiguration(org.springframework.boot.autoconfigure.security.servlet.UserDetailsServiceAutoConfiguration) NullSource(org.junit.jupiter.params.provider.NullSource) Mock(com.arbindo.mimock.entities.Mock) PageImpl(org.springframework.data.domain.PageImpl) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MockRequest(com.arbindo.mimock.manage.mimocks.models.v1.MockRequest) ProcessedMockRequest(com.arbindo.mimock.manage.mimocks.models.v1.ProcessedMockRequest) JsonMapper.convertObjectToJsonString(com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString) RandomDataGenerator.generateRandomAlphabeticString(com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) EmptySource(org.junit.jupiter.params.provider.EmptySource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) NullSource(org.junit.jupiter.params.provider.NullSource)

Example 12 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project mimock by neel1996.

the class MockManagementControllerTest method shouldReturnHttpOk_FilteredListMocksApi_ReturnsNull.

@Test
void shouldReturnHttpOk_FilteredListMocksApi_ReturnsNull() throws Exception {
    // Arrange
    String route = UrlConfig.MOCKS_PATH + "/" + UrlConfig.MOCKS_FILTER;
    lenient().when(mockManagementService.getAllActiveMocks(any(Pageable.class), any(Status.class))).thenReturn(null);
    // Act
    MvcResult result = mockMvc.perform(get(route).param("status", "NONE")).andExpect(status().isOk()).andReturn();
    // Assert
    assertEquals("", result.getResponse().getContentAsString());
}
Also used : Status(com.arbindo.mimock.manage.mimocks.models.v1.Status) HttpStatus(org.springframework.http.HttpStatus) Pageable(org.springframework.data.domain.Pageable) JsonMapper.convertObjectToJsonString(com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString) RandomDataGenerator.generateRandomAlphabeticString(com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 13 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project mimock by neel1996.

the class MockManagementControllerTest method shouldReturnHttpOk_FilteredListMocksApi_ReturnsListOfMocks.

@Test
void shouldReturnHttpOk_FilteredListMocksApi_ReturnsListOfMocks() throws Exception {
    // Arrange
    String route = UrlConfig.MOCKS_PATH + "/" + UrlConfig.MOCKS_FILTER;
    String expectedContentType = "application/json";
    Page<Mock> expectedMocks = generateMocksPageable();
    String expectedResponseBody = convertObjectToJsonString(expectedMocks);
    lenient().when(mockManagementService.getAllActiveMocks(any(Pageable.class), any(Status.class))).thenReturn(expectedMocks);
    // Act
    MvcResult result = mockMvc.perform(get(route).param("status", "NONE")).andExpect(status().isOk()).andExpect(content().contentType(expectedContentType)).andReturn();
    // Assert
    assertEquals(expectedResponseBody, result.getResponse().getContentAsString());
}
Also used : Status(com.arbindo.mimock.manage.mimocks.models.v1.Status) HttpStatus(org.springframework.http.HttpStatus) Pageable(org.springframework.data.domain.Pageable) JsonMapper.convertObjectToJsonString(com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString) RandomDataGenerator.generateRandomAlphabeticString(com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) MvcResult(org.springframework.test.web.servlet.MvcResult) Mock(com.arbindo.mimock.entities.Mock) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) WebMvcTest(org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)

Example 14 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project bmoth by hhu-stups.

the class InitialStateExistsChecker method doInitialStateExistsCheck.

static InitialStateExistsCheckingResult doInitialStateExistsCheck(MachineNode machine) {
    Context ctx = new Context();
    Solver solver = Z3SolverFactory.getZ3Solver(ctx);
    MachineToZ3Translator machineTranslator = new MachineToZ3Translator(machine, ctx);
    final BoolExpr invariant = machineTranslator.getInitialValueConstraint();
    solver.add(invariant);
    Status check = solver.check();
    return new InitialStateExistsCheckingResult(check);
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) MachineToZ3Translator(de.bmoth.backend.z3.MachineToZ3Translator)

Example 15 with Status

use of fi.thl.covid19.exposurenotification.diagnosiskey.v1.Status in project bmoth by hhu-stups.

the class InvariantSatisfiabilityChecker method doInvariantSatisfiabilityCheck.

static InvariantSatisfiabilityCheckingResult doInvariantSatisfiabilityCheck(MachineNode machine) {
    Context ctx = new Context();
    Solver solver = Z3SolverFactory.getZ3Solver(ctx);
    MachineToZ3Translator machineTranslator = new MachineToZ3Translator(machine, ctx);
    final BoolExpr invariant = machineTranslator.getInvariantConstraint();
    solver.add(invariant);
    Status check = solver.check();
    return new InvariantSatisfiabilityCheckingResult(check);
}
Also used : Context(com.microsoft.z3.Context) Status(com.microsoft.z3.Status) BoolExpr(com.microsoft.z3.BoolExpr) Solver(com.microsoft.z3.Solver) MachineToZ3Translator(de.bmoth.backend.z3.MachineToZ3Translator)

Aggregations

Status (com.microsoft.z3.Status)63 BoolExpr (com.microsoft.z3.BoolExpr)55 Test (org.junit.Test)49 Test (org.junit.jupiter.api.Test)20 Expr (com.microsoft.z3.Expr)10 IOException (java.io.IOException)10 JsonMapper.convertObjectToJsonString (com.arbindo.mimock.helpers.general.JsonMapper.convertObjectToJsonString)9 RandomDataGenerator.generateRandomAlphabeticString (com.arbindo.mimock.helpers.general.RandomDataGenerator.generateRandomAlphabeticString)9 Status (com.arbindo.mimock.manage.mimocks.models.v1.Status)9 Context (com.microsoft.z3.Context)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 WebMvcTest (org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest)9 Pageable (org.springframework.data.domain.Pageable)9 HttpStatus (org.springframework.http.HttpStatus)9 MvcResult (org.springframework.test.web.servlet.MvcResult)9 Mock (com.arbindo.mimock.entities.Mock)8 List (java.util.List)7 Solver (com.microsoft.z3.Solver)6 PageImpl (org.springframework.data.domain.PageImpl)6