Skip to content
This repository has been archived by the owner on Jul 15, 2020. It is now read-only.

Commit

Permalink
Add Access Test
Browse files Browse the repository at this point in the history
  • Loading branch information
go0ty committed Feb 29, 2016
1 parent 758f82b commit 6a5ef30
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 1 deletion.
27 changes: 26 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<url>s3://venice-maven-private/snapshot</url>
</repository>
</repositories>


<dependencies>
<dependency>
Expand Down Expand Up @@ -63,6 +63,31 @@
<version>2.1.0</version>
</dependency>

<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-mock</artifactId>
<version>2.0.8</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<properties>
Expand Down
88 changes: 88 additions & 0 deletions src/test/java/access/test/AccessTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package access.test;

import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.when;

import java.util.UUID;

import model.data.DataResource;
import model.data.type.TextResource;
import model.job.metadata.ResourceMetadata;
import model.job.metadata.SpatialMetadata;
import model.response.DataResourceResponse;
import model.response.PiazzaResponse;

import org.junit.Before;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;

import util.PiazzaLogger;
import access.controller.AccessController;
import access.database.MongoAccessor;

/**
* Tests various parts of the Access component.
*
* @author Patrick.Doody
*
*/
public class AccessTests {
@Mock
private PiazzaLogger logger;
@Mock
private MongoAccessor accessor;
@InjectMocks
private AccessController accessController;

/**
* Initialize Mock objects.
*/
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}

@Test
public void getDataTest() {
// Mock a DataResource object to request for. Populate with test
// metadata.
TextResource textData = new TextResource();
textData.content = "This is a test data.";
textData.mimeType = "application/text";

DataResource mockData = new DataResource();
mockData.dataId = UUID.randomUUID().toString();
mockData.dataType = textData;

SpatialMetadata spatialMetadata = new SpatialMetadata();
spatialMetadata.setEpsgCode(4326);
mockData.spatialMetadata = spatialMetadata;

ResourceMetadata metadata = new ResourceMetadata();
metadata.name = "Test data";
metadata.description = "Mockito Test Data";
metadata.classType = "unclassified";
mockData.metadata = metadata;

// Mock the query to respond with the Mock DataResource item
when(accessor.getData(anyString())).thenReturn(mockData);

// Fetch the metadata
PiazzaResponse response = accessController.getData(mockData.dataId);
assertTrue(response instanceof DataResourceResponse);
DataResourceResponse dataResponse = (DataResourceResponse) response;
// Verify the contents of the response match the metadata inputs
assertTrue(dataResponse.data.dataId.equals(mockData.dataId));
assertTrue(dataResponse.data.metadata.classType.equals(metadata.classType));
assertTrue(dataResponse.data.metadata.name.equals(metadata.name));
assertTrue(dataResponse.data.metadata.description.equals(metadata.description));
assertTrue(dataResponse.data.spatialMetadata.getEpsgCode().equals(spatialMetadata.getEpsgCode()));
assertTrue(dataResponse.data.dataType.getType().equals("text"));
TextResource responseTextData = (TextResource) dataResponse.data.dataType;
assertTrue(responseTextData.content.equals(textData.content));
assertTrue(responseTextData.mimeType.equals(textData.mimeType));
}
}

0 comments on commit 6a5ef30

Please sign in to comment.