items:
type: string
'400':
- $ref: '#/components/responses/400Error'
-
+ $ref: '#/components/responses/BadRequest'
+ '401':
+ $ref: '#/components/responses/Unauthorized'
/adapter/{host}:
delete:
responses:
'200':
- description: Successfully deleted an adapter
+ $ref: '#/components/responses/Success'
'400':
- description: Invalid request
+ $ref: '#/components/responses/BadRequest'
'401':
- description: Unauthorized
+ $ref: '#/components/responses/Unauthorized'
'404':
- description: adapter not found
+ $ref: '#/components/responses/NotFound'
/adapter:
post:
$ref: '#/components/schemas/Adapter'
responses:
'200':
- description: Successfully returned a list of adapters
+ $ref: '#/components/responses/Success'
'400':
- $ref: '#/components/responses/400Error'
+ $ref: '#/components/responses/BadRequest'
+ '401':
+ $ref: '#/components/responses/Unauthorized'
components:
schemas:
+ ErrorMessage:
+ type: object
+ title: Error
+ properties:
+ status:
+ type: string
+ message:
+ type: string
+
Adapter:
type: object
properties:
- mechId
responses:
- 400Error:
+ Success:
+ description: Succesfully excecuted
+ BadRequest:
description: Invalid request
content:
application/json:
schema:
- type: object
- properties:
- message:
- type: string
\ No newline at end of file
+ $ref: '#/components/schemas/ErrorMessage'
+ Unauthorized:
+ description: Unhautorized request
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ NotFound:
+ description: Not Found
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+
void testGetAllAdapters() throws Exception {
when(deployer.getAll()).thenReturn(Collections.singletonList("mockResult"));
- mockMvc.perform(get("/adapters/").secure(true).contentType(MediaType.APPLICATION_JSON)).andDo(print())
+ mockMvc.perform(get("/adapters/").secure(true)
+ .contentType(MediaType.APPLICATION_JSON))
+ .andDo(print())
.andExpect(status().isOk()).andExpect(content().string(containsString("mockResult")));
}
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
void testDeleteAdapter() throws Exception {
- mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true).contentType(MediaType.APPLICATION_JSON))
+ mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true)
+ .contentType(MediaType.APPLICATION_JSON))
.andDo(print()).andExpect(status().isOk());
}
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
void testNotFound() throws Exception {
- doThrow(NotFoundException.class).when(deployer).delete(anyString());
-
- mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true).contentType(MediaType.APPLICATION_JSON))
- .andDo(print()).andExpect(status().isNotFound());
+ doThrow(new NotFoundException("172.10.55.3"))
+ .when(deployer)
+ .delete(anyString());
+
+ mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true)
+ .contentType(MediaType.APPLICATION_JSON))
+ .andDo(print())
+ .andExpect(status().isNotFound())
+ .andExpect(content().string(containsString("Adapter 172.10.55.3 is not present.")));
}
@Test
mechId.password("somePass");
adapter.setMechId(mechId);
- mockMvc.perform(post("/adapters/adapter").secure(true).contentType(MediaType.APPLICATION_JSON)
- .content(GSON.toJson(adapter))).andDo(print()).andExpect(status().isOk());
+ mockMvc.perform(post("/adapters/adapter").secure(true)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(GSON.toJson(adapter)))
+ .andDo(print())
+ .andExpect(status().isOk());
}
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
void testAlreadyExist() throws Exception {
-
final Adapter adapter = new Adapter();
adapter.setHost("172.10.55.3");
mechId.password("somePass");
adapter.setMechId(mechId);
- doThrow(AlreadyPresentException.class).when(deployer).create(anyString(), anyString(), anyString());
+ doThrow(new AlreadyPresentException("172.10.55.3"))
+ .when(deployer).create(anyString(), anyString(), anyString());
- mockMvc.perform(post("/adapters/adapter").secure(true).contentType(MediaType.APPLICATION_JSON)
- .content(GSON.toJson(adapter))).andDo(print()).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/adapters/adapter")
+ .secure(true).contentType(MediaType.APPLICATION_JSON)
+ .content(GSON.toJson(adapter)))
+ .andDo(print())
+ .andExpect(status().isBadRequest())
+ .andExpect(content().string(containsString("Adapter 172.10.55.3 already present.")));
}
@Test
@WithMockUser(username = "admin", roles = "ADMIN")
void testMissingArguments() throws Exception {
-
final Adapter adapter = new Adapter();
adapter.setHost("172.10.55.3");
mechId.username("admin");
adapter.setMechId(mechId);
+ mockMvc.perform(post("/adapters/adapter").secure(true)
+ .contentType(MediaType.APPLICATION_JSON)
+ .content(GSON.toJson(adapter)))
+ .andDo(print())
+ .andExpect(status().isBadRequest());
+ }
+
+ @Test
+ void testUnauthorized() throws Exception {
+ mockMvc.perform(post("/adapters/adapter").secure(true))
+ .andDo(print())
+ .andExpect(status().isUnauthorized());
+
+ mockMvc.perform(post("/adapters/adapter").secure(true))
+ .andDo(print())
+ .andExpect(status().isUnauthorized());
+
+ mockMvc.perform(delete("/adapters/adapter/172.10.55.3").secure(true))
+ .andDo(print())
+ .andExpect(status().isUnauthorized());
- mockMvc.perform(post("/adapters/adapter").secure(true).contentType(MediaType.APPLICATION_JSON)
- .content(GSON.toJson(adapter))).andDo(print()).andExpect(status().isBadRequest());
}
@Test