org.springframework.test.web.servlet.MockMvc - java examples

Here are the examples of the java api org.springframework.test.web.servlet.MockMvc taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

155 Examples 7

19 View Complete Implementation : KeyUsageEndpointTest.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = CredhubTestApp.clreplaced)
@ActiveProfiles(value = "unit-test", resolver = DatabaseProfileResolver.clreplaced)
@Transactional
@Ignore
public clreplaced KeyUsageEndpointTest {

    @Autowired
    private WebApplicationContext webApplicationContext;

    private MockMvc mockMvc;

    @Test
    public void GET_whenTheCredentialNameParameterIsMissing_returnsAnAppropriateError() throws Exception {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
        final MockHttpServletRequestBuilder getRequest = get("/api/v1/key-usage").header("Authorization", "Bearer " + ALL_PERMISSIONS_TOKEN);
        mockMvc.perform(getRequest).andExpect(status().isOk()).andExpect(jsonPath("$.active_key", anything())).andExpect(jsonPath("$.inactive_keys", anything())).andExpect(jsonPath("$.unknown_keys", anything()));
    }
}

19 View Complete Implementation : ProfileInfoResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the ProfileInfoResource REST controller.
 *
 * @see ProfileInfoResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { GatewayApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced ProfileInfoResourceIntTest {

    @Mock
    private Environment environment;

    @Mock
    private JHipsterProperties jHipsterProperties;

    private MockMvc restProfileMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        String[] mockProfile = { "test" };
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(mockProfile);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        String[] activeProfiles = { "test" };
        when(environment.getDefaultProfiles()).thenReturn(activeProfiles);
        when(environment.getActiveProfiles()).thenReturn(activeProfiles);
        ProfileInfoResource profileInfoResource = new ProfileInfoResource(environment, jHipsterProperties);
        this.restProfileMockMvc = MockMvcBuilders.standaloneSetup(profileInfoResource).build();
    }

    @Test
    public void getProfileInfoWithRibbon() throws Exception {
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutRibbon() throws Exception {
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(null);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutActiveProfiles() throws Exception {
        String[] emptyProfile = {};
        when(environment.getDefaultProfiles()).thenReturn(emptyProfile);
        when(environment.getActiveProfiles()).thenReturn(emptyProfile);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : RequestHelper.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
public static String generatePreplacedword(final MockMvc mockMvc, final String credentialName, final boolean overwrite, final Integer length, final String token) throws Exception {
    final Map<String, Object> preplacedwordRequestBody = new HashMap() {

        {
            put("name", credentialName);
            put("type", "preplacedword");
        }
    };
    if (overwrite) {
        preplacedwordRequestBody.put("overwrite", true);
    }
    if (length != null) {
        preplacedwordRequestBody.put("parameters", ImmutableMap.of("length", length));
    }
    final String content = JsonTestHelper.serializeToString(preplacedwordRequestBody);
    final MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + token).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(content);
    final String response;
    if (credentialName.length() <= 1024) {
        response = mockMvc.perform(post).andExpect(status().isOk()).andReturn().getResponse().getContentreplacedtring();
    } else {
        response = mockMvc.perform(post).andExpect(status().isBadRequest()).andReturn().getResponse().getContentreplacedtring();
    }
    return response;
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : LegacyCredentialTest.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = CredhubTestApp.clreplaced)
@ActiveProfiles(value = { "unit-test", "unit-test-permissions" }, resolver = DatabaseProfileResolver.clreplaced)
@Transactional
@TestPropertySource(properties = "security.authorization.acls.enabled=true")
@SuppressFBWarnings(value = "SS_SHOULD_BE_STATIC", justification = "Test files generally don't need static fields.")
public clreplaced LegacyCredentialTest {

    private final String CREDENTIAL_NAME = "/some-cred";

    @Autowired
    WebApplicationContext webApplicationContext;

    @Autowired
    CredentialVersionDataService credentialVersionDataService;

    @Autowired
    Encryptor encryptor;

    private MockMvc mockMvc;

    @Before
    public void setup() {
        final ValueCredentialVersionData valueCredentialData = new ValueCredentialVersionData(CREDENTIAL_NAME);
        final ValueCredentialVersion noAclsSecret = new ValueCredentialVersion(valueCredentialData);
        noAclsSecret.setEncryptor(encryptor);
        noAclsSecret.setValue("some value");
        credentialVersionDataService.save(noAclsSecret);
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    }

    @Test
    public void GET_byCredentialName_whenTheCredentialHasNoAclsSet_ReturnsNotFound() throws Exception {
        final MockHttpServletRequestBuilder get = get("/api/v1/data?name=" + CREDENTIAL_NAME).header("Authorization", "Bearer " + NO_PERMISSIONS_TOKEN);
        mockMvc.perform(get).andDo(print()).andExpect(status().isNotFound());
    }
}

19 View Complete Implementation : LogsResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the LogsResource REST controller.
 *
 * @see LogsResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { GatewayApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced LogsResourceIntTest {

    private MockMvc restLogsMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        LogsResource logsResource = new LogsResource();
        this.restLogsMockMvc = MockMvcBuilders.standaloneSetup(logsResource).build();
    }

    @Test
    public void getAllLogs() throws Exception {
        restLogsMockMvc.perform(get("/management/logs")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void changeLogs() throws Exception {
        LoggerVM logger = new LoggerVM();
        logger.setLevel("INFO");
        logger.setName("ROOT");
        restLogsMockMvc.perform(put("/management/logs").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(logger))).andExpect(status().isNoContent());
    }

    @Test
    public void testLogstashAppender() {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        replacedertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.clreplaced);
    }
}

19 View Complete Implementation : ProfileInfoResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the ProfileInfoResource REST controller.
 *
 * @see ProfileInfoResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { AbilityApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced ProfileInfoResourceIntTest {

    @Mock
    private Environment environment;

    @Mock
    private JHipsterProperties jHipsterProperties;

    private MockMvc restProfileMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        String[] mockProfile = { "test" };
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(mockProfile);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        String[] activeProfiles = { "test" };
        when(environment.getDefaultProfiles()).thenReturn(activeProfiles);
        when(environment.getActiveProfiles()).thenReturn(activeProfiles);
        ProfileInfoResource profileInfoResource = new ProfileInfoResource(environment, jHipsterProperties);
        this.restProfileMockMvc = MockMvcBuilders.standaloneSetup(profileInfoResource).build();
    }

    @Test
    public void getProfileInfoWithRibbon() throws Exception {
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutRibbon() throws Exception {
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(null);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutActiveProfiles() throws Exception {
        String[] emptyProfile = {};
        when(environment.getDefaultProfiles()).thenReturn(emptyProfile);
        when(environment.getActiveProfiles()).thenReturn(emptyProfile);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : CredentialFindTestNoAcls.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
@RunWith(SpringRunner.clreplaced)
@ActiveProfiles(value = "unit-test", resolver = DatabaseProfileResolver.clreplaced)
@SpringBootTest(clreplacedes = CredhubTestApp.clreplaced)
@Transactional
@TestPropertySource(properties = "security.authorization.acls.enabled=false")
public clreplaced CredentialFindTestNoAcls {

    @Autowired
    private WebApplicationContext webApplicationContext;

    private MockMvc mockMvc;

    @Before
    public void beforeEach() {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    }

    @Test
    public void findCredentials_byPath_returnsAllCredentialsWhenAclsAreDisabled() throws Exception {
        generateCredentials();
        final MockHttpServletRequestBuilder request = get("/api/v1/data?path=/").header("Authorization", "Bearer " + USER_A_TOKEN).accept(APPLICATION_JSON);
        mockMvc.perform(request).andExpect(status().isOk()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.credentials", hreplacedize(5)));
    }

    private void generateCredentials() throws Exception {
        final List<String> names = Arrays.asList(new String[] { "/path/to/credentialA", "/path/something", "/path/to/credentialB", "/other_path/credentialC", "/another/credentialC" });
        for (final String name : names) {
            generatePreplacedword(mockMvc, name, true, 20, ALL_PERMISSIONS_TOKEN);
        }
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : VersionEndpointTest.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = CredhubTestApp.clreplaced)
@ActiveProfiles(value = "unit-test", resolver = DatabaseProfileResolver.clreplaced)
@Transactional
public clreplaced VersionEndpointTest {

    @Autowired
    private WebApplicationContext webApplicationContext;

    private MockMvc mockMvc;

    @Test
    public void GET_whenTheUserIsAuthenticated_returnsTheServerVersion() throws Exception {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
        final MockHttpServletRequestBuilder getRequest = get("/version").header("Authorization", "Bearer " + AuthConstants.ALL_PERMISSIONS_TOKEN);
        mockMvc.perform(getRequest).andExpect(status().isOk()).andExpect(jsonPath("$.version", anything()));
    }

    @Test
    public void GET_whenTheUserIsNotAuthenticated_returnsAnError() throws Exception {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
        final MockHttpServletRequestBuilder getRequest = get("/version");
        mockMvc.perform(getRequest).andExpect(status().isUnauthorized());
    }
}

19 View Complete Implementation : LogsResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the LogsResource REST controller.
 *
 * @see LogsResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { UmoApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced LogsResourceIntTest {

    private MockMvc restLogsMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        LogsResource logsResource = new LogsResource();
        this.restLogsMockMvc = MockMvcBuilders.standaloneSetup(logsResource).build();
    }

    @Test
    public void getAllLogs() throws Exception {
        restLogsMockMvc.perform(get("/management/logs")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void changeLogs() throws Exception {
        LoggerVM logger = new LoggerVM();
        logger.setLevel("INFO");
        logger.setName("ROOT");
        restLogsMockMvc.perform(put("/management/logs").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(logger))).andExpect(status().isNoContent());
    }

    @Test
    public void testLogstashAppender() {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        replacedertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.clreplaced);
    }
}

19 View Complete Implementation : RequestHelper.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
public static String setPreplacedword(final MockMvc mockMvc, final String credentialName, final String preplacedwordValue, final String token) throws Exception {
    final Map<String, Object> preplacedwordRequestBody = new HashMap() {

        {
            put("name", credentialName);
            put("type", "preplacedword");
            put("value", preplacedwordValue);
        }
    };
    final String content = JsonTestHelper.serializeToString(preplacedwordRequestBody);
    final MockHttpServletRequestBuilder put = put("/api/v1/data").header("Authorization", "Bearer " + token).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(content);
    final String response;
    if (credentialName.length() <= 1024) {
        response = mockMvc.perform(put).andExpect(status().isOk()).andDo(print()).andReturn().getResponse().getContentreplacedtring();
    } else {
        response = mockMvc.perform(put).andExpect(status().isBadRequest()).andDo(print()).andReturn().getResponse().getContentreplacedtring();
    }
    return response;
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : ProfileInfoResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the ProfileInfoResource REST controller.
 *
 * @see ProfileInfoResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = UaaApp.clreplaced)
public clreplaced ProfileInfoResourceIntTest {

    @Mock
    private Environment environment;

    @Mock
    private JHipsterProperties jHipsterProperties;

    private MockMvc restProfileMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        String[] mockProfile = { "test" };
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(mockProfile);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        String[] activeProfiles = { "test" };
        when(environment.getDefaultProfiles()).thenReturn(activeProfiles);
        when(environment.getActiveProfiles()).thenReturn(activeProfiles);
        ProfileInfoResource profileInfoResource = new ProfileInfoResource(environment, jHipsterProperties);
        this.restProfileMockMvc = MockMvcBuilders.standaloneSetup(profileInfoResource).build();
    }

    @Test
    public void getProfileInfoWithRibbon() throws Exception {
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutRibbon() throws Exception {
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(null);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutActiveProfiles() throws Exception {
        String[] emptyProfile = {};
        when(environment.getDefaultProfiles()).thenReturn(emptyProfile);
        when(environment.getActiveProfiles()).thenReturn(emptyProfile);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }
}

19 View Complete Implementation : LogsResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the LogsResource REST controller.
 *
 * @see LogsResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { UmmApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced LogsResourceIntTest {

    private MockMvc restLogsMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        LogsResource logsResource = new LogsResource();
        this.restLogsMockMvc = MockMvcBuilders.standaloneSetup(logsResource).build();
    }

    @Test
    public void getAllLogs() throws Exception {
        restLogsMockMvc.perform(get("/management/logs")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void changeLogs() throws Exception {
        LoggerVM logger = new LoggerVM();
        logger.setLevel("INFO");
        logger.setName("ROOT");
        restLogsMockMvc.perform(put("/management/logs").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(logger))).andExpect(status().isNoContent());
    }

    @Test
    public void testLogstashAppender() {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        replacedertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.clreplaced);
    }
}

19 View Complete Implementation : ProfileInfoResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the ProfileInfoResource REST controller.
 *
 * @see ProfileInfoResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { UmdApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced ProfileInfoResourceIntTest {

    @Mock
    private Environment environment;

    @Mock
    private JHipsterProperties jHipsterProperties;

    private MockMvc restProfileMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        String[] mockProfile = { "test" };
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(mockProfile);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        String[] activeProfiles = { "test" };
        when(environment.getDefaultProfiles()).thenReturn(activeProfiles);
        when(environment.getActiveProfiles()).thenReturn(activeProfiles);
        ProfileInfoResource profileInfoResource = new ProfileInfoResource(environment, jHipsterProperties);
        this.restProfileMockMvc = MockMvcBuilders.standaloneSetup(profileInfoResource).build();
    }

    @Test
    public void getProfileInfoWithRibbon() throws Exception {
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutRibbon() throws Exception {
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(null);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutActiveProfiles() throws Exception {
        String[] emptyProfile = {};
        when(environment.getDefaultProfiles()).thenReturn(emptyProfile);
        when(environment.getActiveProfiles()).thenReturn(emptyProfile);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : RequestHelper.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
public static String generateRsa(final MockMvc mockMvc, final String credentialName, final boolean overwrite, final Integer length) throws Exception {
    final Map<String, Object> rsaRequestBody = new HashMap() {

        {
            put("name", credentialName);
            put("type", "rsa");
        }
    };
    if (overwrite) {
        rsaRequestBody.put("overwrite", true);
    }
    if (length != null) {
        rsaRequestBody.put("parameters", ImmutableMap.of("key_length", length));
    }
    final String content = JsonTestHelper.serializeToString(rsaRequestBody);
    final MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(content);
    final String response = mockMvc.perform(post).andExpect(status().isOk()).andReturn().getResponse().getContentreplacedtring();
    return response;
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : RequestHelper.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
public static String generateSsh(final MockMvc mockMvc, final String credentialName, final boolean overwrite, final Integer length, final String sshComment) throws Exception {
    final Map<String, Object> sshRequestBody = new HashMap() {

        {
            put("name", credentialName);
            put("type", "ssh");
        }
    };
    if (overwrite) {
        sshRequestBody.put("overwrite", true);
    }
    final Map parameters = new HashMap<String, Object>();
    if (length != null) {
        parameters.put("key_length", length);
    }
    if (sshComment != null) {
        parameters.put("ssh_comment", sshComment);
    }
    sshRequestBody.put("parameters", parameters);
    final String content = JsonTestHelper.serializeToString(sshRequestBody);
    final MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(content);
    final String response = mockMvc.perform(post).andExpect(status().isOk()).andReturn().getResponse().getContentreplacedtring();
    return response;
}

19 View Complete Implementation : LogsResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the LogsResource REST controller.
 *
 * @see LogsResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { UmuApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced LogsResourceIntTest {

    private MockMvc restLogsMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        LogsResource logsResource = new LogsResource();
        this.restLogsMockMvc = MockMvcBuilders.standaloneSetup(logsResource).build();
    }

    @Test
    public void getAllLogs() throws Exception {
        restLogsMockMvc.perform(get("/management/logs")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void changeLogs() throws Exception {
        LoggerVM logger = new LoggerVM();
        logger.setLevel("INFO");
        logger.setName("ROOT");
        restLogsMockMvc.perform(put("/management/logs").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(logger))).andExpect(status().isNoContent());
    }

    @Test
    public void testLogstashAppender() {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        replacedertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.clreplaced);
    }
}

19 View Complete Implementation : RequestHelper.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
public static String generateCertificateCredential(final MockMvc mockMvc, final String credentialName, final boolean overwrite, final String commonName, final String caName, final String token) throws Exception {
    final Map<String, Object> certRequestBody = new HashMap() {

        {
            put("name", credentialName);
            put("type", "certificate");
        }
    };
    if (overwrite) {
        certRequestBody.put("overwrite", true);
    }
    final Map parameters = new HashMap<String, Object>();
    if (caName == null) {
        parameters.put("self_sign", true);
        parameters.put("is_ca", true);
    } else {
        parameters.put("ca", caName);
    }
    parameters.put("common_name", commonName);
    certRequestBody.put("parameters", parameters);
    final String content = JsonTestHelper.serializeToString(certRequestBody);
    final MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + token).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(content);
    final String response = mockMvc.perform(post).andExpect(status().isOk()).andReturn().getResponse().getContentreplacedtring();
    return response;
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : UpdatingACredentialTest.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
@RunWith(SpringRunner.clreplaced)
@ActiveProfiles(profiles = "unit-test", resolver = DatabaseProfileResolver.clreplaced)
@SpringBootTest(clreplacedes = CredhubTestApp.clreplaced)
@Transactional
public clreplaced UpdatingACredentialTest {

    @Autowired
    WebApplicationContext webApplicationContext;

    private MockMvc mockMvc;

    private String preplacedwordName;

    @Before
    public void beforeEach() {
        preplacedwordName = "test-preplacedword";
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    }

    @Test
    public void post_shouldAllowTheCredentialToBeUpdated() throws Exception {
        String requestBody = "{" + "\"type\":\"preplacedword\"," + "\"name\":\"" + preplacedwordName + "\"," + "\"overwrite\":true" + "}";
        MvcResult result = mockMvc.perform(post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(requestBody)).andExpect(status().is2xxSuccessful()).andReturn();
        JSONObject jsonObject = new JSONObject(result.getResponse().getContentreplacedtring());
        final String firstPreplacedword = jsonObject.getString("value");
        requestBody = "{" + "\"type\":\"preplacedword\"," + "\"name\":\"" + preplacedwordName + "\"," + "\"overwrite\":true" + "}";
        result = mockMvc.perform(post("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(requestBody)).andExpect(status().is2xxSuccessful()).andReturn();
        jsonObject = new JSONObject(result.getResponse().getContentreplacedtring());
        final String lastPreplacedword = jsonObject.getString("value");
        replacedertThat(firstPreplacedword, is(not(equalTo(lastPreplacedword))));
    }

    @Test
    public void put_shouldAllowTheCredentialToBeUpdated() throws Exception {
        String requestBody = "{" + "\"type\":\"preplacedword\"," + "\"name\":\"" + preplacedwordName + "\",\"value\":\"ORIGINAL-VALUE\"" + "}";
        mockMvc.perform(put("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(requestBody)).andExpect(status().is2xxSuccessful()).andExpect(jsonPath("$.value").value("ORIGINAL-VALUE"));
        requestBody = "{" + "\"type\":\"preplacedword\"," + "\"name\":\"" + preplacedwordName + "\",\"value\":\"NEW-VALUE\"" + "}";
        mockMvc.perform(put("/api/v1/data").header("Authorization", "Bearer " + AuthConstants.ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(requestBody)).andExpect(status().is2xxSuccessful()).andExpect(jsonPath("$.value").value("NEW-VALUE"));
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : DefaultExceptionHandlerTest.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
@RunWith(SpringRunner.clreplaced)
@ActiveProfiles(value = "unit-test", resolver = DatabaseProfileResolver.clreplaced)
@SpringBootTest(clreplacedes = CredhubTestApp.clreplaced)
@Transactional
public clreplaced DefaultExceptionHandlerTest {

    @MockBean
    private DefaultCredentialsHandler credentialsHandler;

    @Autowired
    private WebApplicationContext webApplicationContext;

    private MockMvc mockMvc;

    @Before
    public void setUp() {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    }

    @Test
    public void wheGenericExceptionIsThrown_returns500() throws Exception {
        when(credentialsHandler.getNCredentialVersions(eq("/foo"), any())).thenThrow(new RuntimeException());
        final MockHttpServletRequestBuilder request = get("/api/v1/data?name=foo").header("Authorization", "Bearer " + AuthConstants.ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON);
        final String expectedError = "An application error occurred. Please contact your CredHub administrator.";
        mockMvc.perform(request).andExpect(status().isInternalServerError()).andExpect(content().contentTypeCompatibleWith(APPLICATION_JSON)).andExpect(jsonPath("$.error").value(ErrorMessages.INTERNAL_SERVER_ERROR));
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : RequestHelper.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
public static String generateUser(final MockMvc mockMvc, final String credentialName, final boolean overwrite, final Integer length, final String username, final boolean excludeUpper) throws Exception {
    final Map<String, Object> userRequestBody = new HashMap() {

        {
            put("name", credentialName);
            put("type", "user");
        }
    };
    if (overwrite) {
        userRequestBody.put("overwrite", true);
    }
    final Map parameters = new HashMap<String, Object>();
    if (length != null) {
        parameters.put("length", length);
    }
    if (username != null) {
        parameters.put("username", username);
    }
    if (excludeUpper) {
        parameters.put("exclude_upper", true);
    }
    userRequestBody.put("parameters", parameters);
    final String content = JsonTestHelper.serializeToString(userRequestBody);
    final MockHttpServletRequestBuilder post = post("/api/v1/data").header("Authorization", "Bearer " + ALL_PERMISSIONS_TOKEN).accept(APPLICATION_JSON).contentType(APPLICATION_JSON).content(content);
    final String response = mockMvc.perform(post).andExpect(status().isOk()).andReturn().getResponse().getContentreplacedtring();
    return response;
}

19 View Complete Implementation : LogsResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the LogsResource REST controller.
 *
 * @see LogsResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { UmdApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced LogsResourceIntTest {

    private MockMvc restLogsMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        LogsResource logsResource = new LogsResource();
        this.restLogsMockMvc = MockMvcBuilders.standaloneSetup(logsResource).build();
    }

    @Test
    public void getAllLogs() throws Exception {
        restLogsMockMvc.perform(get("/management/logs")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void changeLogs() throws Exception {
        LoggerVM logger = new LoggerVM();
        logger.setLevel("INFO");
        logger.setName("ROOT");
        restLogsMockMvc.perform(put("/management/logs").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(logger))).andExpect(status().isNoContent());
    }

    @Test
    public void testLogstashAppender() {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        replacedertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.clreplaced);
    }
}

19 View Complete Implementation : CertificateGenerateWithoutAclEnforcementTest.java
Copyright Apache License 2.0
Author : cloudfoundry-incubator
@RunWith(SpringRunner.clreplaced)
@ActiveProfiles(value = "unit-test", resolver = DatabaseProfileResolver.clreplaced)
@SpringBootTest(clreplacedes = CredhubTestApp.clreplaced)
@TestPropertySource(properties = "security.authorization.acls.enabled=false")
@Transactional
public clreplaced CertificateGenerateWithoutAclEnforcementTest {

    private static final String CREDENTIAL_NAME = "some-certificate";

    private static final String CA_NAME = "some-ca";

    @Autowired
    private WebApplicationContext webApplicationContext;

    private MockMvc mockMvc;

    @Before
    public void beforeEach() throws Exception {
        mockMvc = MockMvcBuilders.webAppContextSetup(webApplicationContext).apply(springSecurity()).build();
    }

    @Test
    public void certificateGeneration_whenPermissionsAreNotEnforced_WithValidCa_generatesTheCertificate() throws Exception {
        RequestHelper.generateCa(mockMvc, CA_NAME, AuthConstants.NO_PERMISSIONS_TOKEN);
        // This request uses the PreplacedWORD GRANT TOKEN under the hood and hence should fail if permissions are enforced.
        final String firstResponse = RequestHelper.generateCertificateCredential(mockMvc, CREDENTIAL_NAME, false, "some-common-name", CA_NAME, ALL_PERMISSIONS_TOKEN);
        replacedertThat(firstResponse, containsString(CREDENTIAL_NAME));
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : ProfileInfoResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the ProfileInfoResource REST controller.
 *
 * @see ProfileInfoResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { UmoApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced ProfileInfoResourceIntTest {

    @Mock
    private Environment environment;

    @Mock
    private JHipsterProperties jHipsterProperties;

    private MockMvc restProfileMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        String[] mockProfile = { "test" };
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(mockProfile);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        String[] activeProfiles = { "test" };
        when(environment.getDefaultProfiles()).thenReturn(activeProfiles);
        when(environment.getActiveProfiles()).thenReturn(activeProfiles);
        ProfileInfoResource profileInfoResource = new ProfileInfoResource(environment, jHipsterProperties);
        this.restProfileMockMvc = MockMvcBuilders.standaloneSetup(profileInfoResource).build();
    }

    @Test
    public void getProfileInfoWithRibbon() throws Exception {
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutRibbon() throws Exception {
        JHipsterProperties.Ribbon ribbon = new JHipsterProperties.Ribbon();
        ribbon.setDisplayOnActiveProfiles(null);
        when(jHipsterProperties.getRibbon()).thenReturn(ribbon);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void getProfileInfoWithoutActiveProfiles() throws Exception {
        String[] emptyProfile = {};
        when(environment.getDefaultProfiles()).thenReturn(emptyProfile);
        when(environment.getActiveProfiles()).thenReturn(emptyProfile);
        restProfileMockMvc.perform(get("/api/profile-info")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : ComposerResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the ProfileInfoResource REST controller.
 *
 * @see ProfileInfoResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { UcomposerApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced ComposerResourceIntTest {

    private static final String solutonId = "bc41200d-943f-4d44-a13c-9e64abf2e08b";

    private static final String modelMethod = "start_add";

    @Autowired
    ComposerService composerService;

    @Autowired
    ConfigurationProperties configurationProperties;

    @Autowired
    private MappingJackson2HttpMessageConverter jacksonMessageConverter;

    @Autowired
    private PageableHandlerMethodArgumentResolver pageableArgumentResolver;

    @Autowired
    private ExceptionTranslator exceptionTranslator;

    @Mock
    private Environment environment;

    @Mock
    private JHipsterProperties jHipsterProperties;

    private MockMvc restComposerMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        final ComposerResource composerResource = new ComposerResource(composerService);
        this.restComposerMockMvc = MockMvcBuilders.standaloneSetup(composerResource).setCustomArgumentResolvers(pageableArgumentResolver).setControllerAdvice(exceptionTranslator).setConversionService(createFormattingConversionService()).setMessageConverters(jacksonMessageConverter).build();
    }

    @Test
    public void orchestrate() throws Exception {
        String requestBody = "{" + "\"one_data\": 10" + "}";
        restComposerMockMvc.perform(post("/composer/" + solutonId + "/" + modelMethod).contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(requestBody)).header("Content-Type", "application/json").header("Accept", "application/json")).andExpect(status().is2xxSuccessful());
    }
    // @Test
    // public void runNode() throws Exception {
    // MultiValueMap<String,String> requestHeader = new HttpHeaders();
    // List<String> list = new ArrayList<>();
    // list.add("application/json");
    // requestHeader.put("Content-Type", list);
    // requestHeader.put("Accept", list);
    // String requestBody = "{" + "\"one_data\": 10" + "}";
    // composerService.orchestrate(solutonId, modelMethod, requestBody, requestHeader);
    // }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated() throws Exception {
    props.getCors().setAllowedOrigins(null);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : LogsResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the LogsResource REST controller.
 *
 * @see LogsResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = { AbilityApp.clreplaced, SecurityBeanOverrideConfiguration.clreplaced })
public clreplaced LogsResourceIntTest {

    private MockMvc restLogsMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        LogsResource logsResource = new LogsResource();
        this.restLogsMockMvc = MockMvcBuilders.standaloneSetup(logsResource).build();
    }

    @Test
    public void getAllLogs() throws Exception {
        restLogsMockMvc.perform(get("/management/logs")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void changeLogs() throws Exception {
        LoggerVM logger = new LoggerVM();
        logger.setLevel("INFO");
        logger.setName("ROOT");
        restLogsMockMvc.perform(put("/management/logs").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(logger))).andExpect(status().isNoContent());
    }

    @Test
    public void testLogstashAppender() {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        replacedertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.clreplaced);
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : LogsResourceIntTest.java
Copyright Apache License 2.0
Author : cube-ai
/**
 * Test clreplaced for the LogsResource REST controller.
 *
 * @see LogsResource
 */
@RunWith(SpringRunner.clreplaced)
@SpringBootTest(clreplacedes = UaaApp.clreplaced)
public clreplaced LogsResourceIntTest {

    private MockMvc restLogsMockMvc;

    @Before
    public void setup() {
        MockitoAnnotations.initMocks(this);
        LogsResource logsResource = new LogsResource();
        this.restLogsMockMvc = MockMvcBuilders.standaloneSetup(logsResource).build();
    }

    @Test
    public void getAllLogs() throws Exception {
        restLogsMockMvc.perform(get("/management/logs")).andExpect(status().isOk()).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE));
    }

    @Test
    public void changeLogs() throws Exception {
        LoggerVM logger = new LoggerVM();
        logger.setLevel("INFO");
        logger.setName("ROOT");
        restLogsMockMvc.perform(put("/management/logs").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(logger))).andExpect(status().isNoContent());
    }

    @Test
    public void testLogstashAppender() {
        LoggerContext context = (LoggerContext) LoggerFactory.getILoggerFactory();
        replacedertThat(context.getLogger("ROOT").getAppender("ASYNC_LOGSTASH")).isInstanceOf(AsyncAppender.clreplaced);
    }
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterOnOtherPath() throws Exception {
    props.getCors().setAllowedOrigins(Collections.singletonList("*"));
    props.getCors().setAllowedMethods(Arrays.asList("GET", "POST", "PUT", "DELETE"));
    props.getCors().setAllowedHeaders(Collections.singletonList("*"));
    props.getCors().setMaxAge(1800L);
    props.getCors().setAllowCredentials(true);
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/test/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}

19 View Complete Implementation : WebConfigurerTest.java
Copyright Apache License 2.0
Author : cube-ai
@Test
public void testCorsFilterDeactivated2() throws Exception {
    props.getCors().setAllowedOrigins(new ArrayList<>());
    MockMvc mockMvc = MockMvcBuilders.standaloneSetup(new WebConfigurerTestController()).addFilters(webConfigurer.corsFilter()).build();
    mockMvc.perform(get("/api/test-cors").header(HttpHeaders.ORIGIN, "other.domain.com")).andExpect(status().isOk()).andExpect(header().doesNotExist(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN));
}