Skip to content

Commit

Permalink
[#162202420] refactored find payload method
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Farris committed Dec 4, 2018
1 parent 3485dc7 commit 696de60
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 15 deletions.
Expand Up @@ -101,13 +101,16 @@ public Map<ArkId, JsonNode> findAll() {
}

/**
*
* Find the deployment specification based on implementation ark id
* @param arkId implementation ark id
* @return JsonNode deployment specification
*/
public JsonNode findDeploymentSpecification(ArkId arkId) {

log.info("find deployment specification for " + arkId.getDashArkImplementation());

throw new RuntimeException("not implemented yet");
return findDeploymentSpecification(arkId, findImplementationMetadata(arkId));

}

/**
Expand Down Expand Up @@ -144,19 +147,15 @@ public JsonNode findKnowledgeObjectMetadata(ArkId arkId) {
return dataStore.getMetadata(arkId.getDashArk());
}

public JsonNode findPayload(ArkId arkId) {

log.info("find payload for " + arkId.getDashArkImplementation());

return null;

}
public byte[] findPayload(ArkId arkId, String implementationPath) {

public JsonNode findPayload(ArkId arkId, JsonNode implementationNode) {
String payloadPath = Paths.get(arkId.getDashArkImplementation(),
implementationPath).toString();

log.info("find payload for " + arkId.getDashArkImplementation());
log.info("find payload for " + payloadPath);

return null;
return dataStore.getBinary(payloadPath);

}

Expand Down Expand Up @@ -234,7 +233,9 @@ public ArkId importZip(ArkId arkId, MultipartFile zippedKO) {
/**
* Loads a YMAL specification file (service or deployment) and maps to a JSON node
*
* @return specification node
* @param arkId implementation ark id
* @param uriPath path to specification file
* @return JsonNode representing YMAL specification file
*/
protected JsonNode loadSpecificationNode(ArkId arkId, String uriPath) {
try {
Expand Down
@@ -1,5 +1,6 @@
package org.kgrid.shelf.repository;

import static junit.framework.TestCase.assertNull;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
Expand All @@ -19,7 +20,6 @@
import org.junit.rules.TemporaryFolder;
import org.junit.runner.RunWith;
import org.kgrid.shelf.domain.ArkId;
import org.kgrid.shelf.domain.KnowledgeObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.ContextConfiguration;
Expand Down Expand Up @@ -133,13 +133,49 @@ public void findServiceSpecificationNotFound() throws IOException, URISyntaxExce
ArkId arkId = new ArkId("hello-world/xxxx");
JsonNode serviceSpecNode = repository.findServiceSpecification(arkId);

}
@Test
public void findDeploymentSpecification() throws IOException, URISyntaxException {

URL zipStream = FilesystemCDOStoreTest.class.getResource("/fixtures/hello-world.zip");
byte[] zippedKO = Files.readAllBytes(Paths.get(zipStream.toURI()));

MockMultipartFile koZip = new MockMultipartFile("ko", "hello-world-.zip", "application/zip", zippedKO);;
repository.importZip(arkId, koZip);

ArkId arkId = new ArkId("hello-world/koio.v1");
JsonNode serviceSpecNode = repository.findDeploymentSpecification(arkId);
assertNotNull( serviceSpecNode );


}

@Test
public void findPayload() {
public void findPayload() throws IOException, URISyntaxException {

URL zipStream = FilesystemCDOStoreTest.class.getResource("/fixtures/hello-world.zip");
byte[] zippedKO = Files.readAllBytes(Paths.get(zipStream.toURI()));

MockMultipartFile koZip = new MockMultipartFile("ko", "hello-world-.zip", "application/zip", zippedKO);;
repository.importZip(arkId, koZip);

ArkId arkId = new ArkId("hello-world/koio.v1");
byte[] payload = repository.findPayload(arkId, "welcome.js");
assertNotNull( payload );

}

@Test
public void findDeploymentSpecification() {
public void findPayloadNotFound() throws IOException, URISyntaxException {

URL zipStream = FilesystemCDOStoreTest.class.getResource("/fixtures/hello-world.zip");
byte[] zippedKO = Files.readAllBytes(Paths.get(zipStream.toURI()));

MockMultipartFile koZip = new MockMultipartFile("ko", "hello-world-.zip", "application/zip", zippedKO);;
repository.importZip(arkId, koZip);

ArkId arkId = new ArkId("hello-world/koio.v1");
byte[] payload = repository.findPayload(arkId, "one/two/three/welcome.js");
assertNull( payload );
}
}

0 comments on commit 696de60

Please sign in to comment.