- GET /features/{id}/quicklook added and tested on controller level
This commit is contained in:
parent
90d3f81aac
commit
8e779b587d
@ -32,4 +32,10 @@ public class FeaturesController {
|
||||
return dataService.getFeature(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Unable to find feature"));
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/features/{id}/quicklook", method = RequestMethod.GET, produces = "image/png")
|
||||
@ResponseBody
|
||||
public byte[] quicklookByFeatureId(@PathVariable String id) {
|
||||
return dataService.getPicture(id).orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Unable to find feature"));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package click.poweronoff.satellite.domain;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.Getter;
|
||||
@ -18,4 +19,7 @@ public class Feature {
|
||||
private long endViewingDate;
|
||||
|
||||
private String missionName;
|
||||
|
||||
@JsonIgnore
|
||||
private byte[] picture;
|
||||
}
|
||||
|
@ -26,10 +26,10 @@ public interface DataService {
|
||||
|
||||
|
||||
/**
|
||||
* returned a picture as a Base64 encoded String representation for given feature id
|
||||
* returned a picture as a byte[] representation for given feature id
|
||||
*
|
||||
* @param featureId feature id
|
||||
* @return a Base64 encoded String representation for a picture
|
||||
* @return a picture as a byte[]
|
||||
*/
|
||||
String getPictureAsB64(final String featureId);
|
||||
Optional<byte[]> getPicture(final String featureId);
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ public class DataServiceImpl implements DataService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPictureAsB64(String featureId) {
|
||||
return null;
|
||||
public Optional<byte[]> getPicture(String featureId) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ public class FeaturesControllerTest {
|
||||
|
||||
@Test
|
||||
public void getFeaturesShouldReturnDefaultMessage() throws Exception {
|
||||
when(dataService.getAllFeatures()).thenReturn(List.of(new Feature("feature-id", 123L, 234L, 345L, "mission")));
|
||||
when(dataService.getAllFeatures()).thenReturn(List.of(createTestFeature()));
|
||||
this.mockMvc.perform(get("/features")).andDo(print())
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
|
||||
@ -48,7 +48,7 @@ public class FeaturesControllerTest {
|
||||
|
||||
@Test
|
||||
public void getFeatureByIdShouldReturnAMessage() throws Exception {
|
||||
when(dataService.getFeature(anyString())).thenReturn(Optional.of(new Feature("feature-id", 123L, 234L, 345L, "mission")));
|
||||
when(dataService.getFeature(anyString())).thenReturn(Optional.of(createTestFeature()));
|
||||
this.mockMvc.perform(get("/features/feature-id"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.APPLICATION_JSON));
|
||||
@ -62,4 +62,25 @@ public class FeaturesControllerTest {
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getQuicklookByFeatureIdShouldReturnNotFound() throws Exception {
|
||||
when(dataService.getPicture(anyString())).thenReturn(Optional.empty());
|
||||
this.mockMvc.perform(get("/features/non-existing-feature/quicklook"))
|
||||
.andExpect(status().isNotFound());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getQuicklookByFeatureIdShouldReturnAPicture() throws Exception {
|
||||
Feature testFeature = createTestFeature();
|
||||
|
||||
when(dataService.getPicture(anyString())).thenReturn(Optional.of(testFeature.getPicture()));
|
||||
this.mockMvc.perform(get("/features/existing-feature/quicklook"))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(content().contentType(MediaType.IMAGE_PNG))
|
||||
.andExpect(content().bytes(testFeature.getPicture()));
|
||||
}
|
||||
|
||||
private Feature createTestFeature() {
|
||||
return new Feature("feature-id", 123L, 234L, 345L, "mission", "test-picture".getBytes());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user