@Test
public void createAppTest() throws Exception {

	OadrAppCreateDto dto = new OadrAppCreateDto();
	dto.setCommonName("app");
	dto.setUsername("app");
	dto.setAuthenticationType("login");
	dto.setPassword("pass");
	byte[] content = mapper.writeValueAsBytes(dto);
	// forbidden
	this.mockMvc
			.perform(MockMvcRequestBuilders.post(ACCOUNT_APP_URL).content(content)
					.header("Content-Type", "application/json").with(user))
			.andExpect(MockMvcResultMatchers.status().is(HttpStatus.FORBIDDEN_403));
	// already created app
	this.mockMvc
			.perform(MockMvcRequestBuilders.post(ACCOUNT_APP_URL).content(content)
					.header("Content-Type", "application/json").with(admin))
			.andExpect(MockMvcResultMatchers.status().is(HttpStatus.NOT_ACCEPTABLE_406));
	// create login auth app no certificate gen
	dto = new OadrAppCreateDto();
	dto.setCommonName("myapp");
	dto.setUsername("myapp");
	dto.setAuthenticationType("login");
	dto.setPassword("pass");
	content = mapper.writeValueAsBytes(dto);
	MvcResult andReturn = this.mockMvc
			.perform(MockMvcRequestBuilders.post(ACCOUNT_APP_URL).content(content)
					.header("Content-Type", "application/json").with(admin))
			.andExpect(MockMvcResultMatchers.status().is(HttpStatus.CREATED_201)).andReturn();
	assertEquals(0, andReturn.getResponse().getContentLength());
	// verify app has been created
	OadrApp findByUsername = oadrAppService.findByUsername("myapp");
	assertNotNull(findByUsername);
	oadrAppService.delete(findByUsername);
	// create x509 auth app no certificate gen
	dto = new OadrAppCreateDto();
	dto.setCommonName("myapp");
	dto.setUsername("myapp");
	dto.setAuthenticationType("x509");
	content = mapper.writeValueAsBytes(dto);
	andReturn = this.mockMvc
			.perform(MockMvcRequestBuilders.post(ACCOUNT_APP_URL).content(content)
					.header("Content-Type", "application/json").with(admin))
			.andExpect(MockMvcResultMatchers.status().is(HttpStatus.CREATED_201)).andReturn();
	assertEquals(0, andReturn.getResponse().getContentLength());
	// verify app has been created
	findByUsername = oadrAppService.findByUsername("myapp");
	assertNotNull(findByUsername);
	oadrAppService.delete(findByUsername);
	// create x509 app user rsa certificate gen
	dto = new OadrAppCreateDto();
	dto.setCommonName("myapp");
	dto.setAuthenticationType("x509");
	dto.setNeedCertificateGeneration("rsa");
	content = mapper.writeValueAsBytes(dto);
	andReturn = this.mockMvc
			.perform(MockMvcRequestBuilders.post(ACCOUNT_APP_URL).content(content)
					.header("Content-Type", "application/json").with(admin))
			.andExpect(MockMvcResultMatchers.status().is(HttpStatus.CREATED_201)).andReturn();
	assertNotEquals(0, andReturn.getResponse().getContentLength());
	// verify app has been created
	assertNotNull(andReturn.getResponse().getHeader("x-username"));
	findByUsername = oadrAppService.findByUsername(andReturn.getResponse().getHeader("x-username"));
	assertNotNull(findByUsername);
	oadrAppService.delete(findByUsername);
	// create x509 auth app ecc certificate gen
	dto = new OadrAppCreateDto();
	dto.setCommonName("myapp");
	dto.setAuthenticationType("x509");
	dto.setNeedCertificateGeneration("ecc");
	content = mapper.writeValueAsBytes(dto);
	andReturn = this.mockMvc
			.perform(MockMvcRequestBuilders.post(ACCOUNT_APP_URL).content(content)
					.header("Content-Type", "application/json").with(admin))
			.andExpect(MockMvcResultMatchers.status().is(HttpStatus.CREATED_201)).andReturn();
	assertNotEquals(0, andReturn.getResponse().getContentLength());
	// verify app has been created
	assertNotNull(andReturn.getResponse().getHeader("x-username"));
	findByUsername = oadrAppService.findByUsername(andReturn.getResponse().getHeader("x-username"));
	assertNotNull(findByUsername);
	oadrAppService.delete(findByUsername);
}