- added a necessary DTO's and JsonFileRepository, what enables the application to serialize json-file in to DTO's
- added application configuration properties to configure the test data file path, what can be overridden by the user
This commit is contained in:
parent
25b6beb82c
commit
f448776dd4
9
pom.xml
9
pom.xml
@ -23,7 +23,7 @@
|
|||||||
<lombok.version>1.18.12</lombok.version>
|
<lombok.version>1.18.12</lombok.version>
|
||||||
<mockito.version>3.3.0</mockito.version>
|
<mockito.version>3.3.0</mockito.version>
|
||||||
<junit.version>4.12</junit.version>
|
<junit.version>4.12</junit.version>
|
||||||
<hamcrest.version>2.1</hamcrest.version>
|
<assertj-guava.version>3.3.0</assertj-guava.version>
|
||||||
</properties>
|
</properties>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
@ -65,10 +65,11 @@
|
|||||||
<version>${junit.version}</version>
|
<version>${junit.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.hamcrest</groupId>
|
<groupId>org.assertj</groupId>
|
||||||
<artifactId>hamcrest</artifactId>
|
<artifactId>assertj-guava</artifactId>
|
||||||
<version>2.1</version>
|
<version>${assertj-guava.version}</version>
|
||||||
<scope>test</scope>
|
<scope>test</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
@ -0,0 +1,33 @@
|
|||||||
|
package click.poweronoff.satellite.repository;
|
||||||
|
|
||||||
|
import click.poweronoff.satellite.repository.dto.FeaturesCollection;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.FileReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class JsonFileRepository {
|
||||||
|
|
||||||
|
@Value("${storage.file.path}")
|
||||||
|
private String filePath;
|
||||||
|
|
||||||
|
private ObjectMapper objectMapper;
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
public void initRepository() {
|
||||||
|
objectMapper = new ObjectMapper();
|
||||||
|
}
|
||||||
|
|
||||||
|
public FeaturesCollection[] readAllFeatures() throws IOException {
|
||||||
|
FileReader fileReader = new FileReader(filePath);
|
||||||
|
BufferedReader reader = new BufferedReader(fileReader);
|
||||||
|
FeaturesCollection[] features = objectMapper.readValue(reader, FeaturesCollection[].class);
|
||||||
|
reader.close();
|
||||||
|
return features;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,15 @@
|
|||||||
|
package click.poweronoff.satellite.repository.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Data
|
||||||
|
public class Acquisition {
|
||||||
|
|
||||||
|
private String beginViewingDate;
|
||||||
|
|
||||||
|
private String endViewingDate;
|
||||||
|
|
||||||
|
private String missionName;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package click.poweronoff.satellite.repository.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Data
|
||||||
|
public class Features {
|
||||||
|
private Properties properties;
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
package click.poweronoff.satellite.repository.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Data
|
||||||
|
public class FeaturesCollection {
|
||||||
|
private Features[] features;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
package click.poweronoff.satellite.repository.dto;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||||
|
@Data
|
||||||
|
public class Properties {
|
||||||
|
|
||||||
|
@JsonProperty
|
||||||
|
private String id;
|
||||||
|
@JsonProperty
|
||||||
|
private String timestamp;
|
||||||
|
@JsonProperty
|
||||||
|
private String quicklook;
|
||||||
|
@JsonProperty
|
||||||
|
private Acquisition acquisition;
|
||||||
|
}
|
@ -1 +1,2 @@
|
|||||||
|
# configuration for the json data storage relative path
|
||||||
|
storage.file.path=json/source-data.json
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package click.poweronoff.satellite.repository;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
|
||||||
|
@SpringBootTest
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
public class JsonFileRepositoryTest {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private JsonFileRepository repository;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void readAllFeaturesShouldReturnAllFeatures() throws IOException {
|
||||||
|
assertThat(repository.readAllFeatures()).isNotEmpty();
|
||||||
|
assertThat(repository.readAllFeatures()).hasSize(14);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user