Commit 32e580e0 authored by Spiros Koulouzis's avatar Spiros Koulouzis

added check to test the was trying to connect to sure-tosca

parent 4abc6571
...@@ -167,7 +167,8 @@ public class DRIPService { ...@@ -167,7 +167,8 @@ public class DRIPService {
return toscaTemplate; return toscaTemplate;
} }
void deleteActions(ToscaTemplate toscaTemplate) throws ApiException, TypeExeption { void deleteActions(ToscaTemplate toscaTemplate) throws ApiException, TypeExeption, IOException {
helper.uploadToscaTemplate(toscaTemplate);
List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates(); List<NodeTemplateMap> vmTopologies = helper.getVMTopologyTemplates();
for (NodeTemplateMap vmTopology : vmTopologies){ for (NodeTemplateMap vmTopology : vmTopologies){
CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology); CloudsStormSubTopology.StatusEnum status = helper.getVMTopologyTemplateStatus(vmTopology);
......
...@@ -28,6 +28,8 @@ import java.io.File; ...@@ -28,6 +28,8 @@ import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -37,12 +39,14 @@ import java.util.logging.Level; ...@@ -37,12 +39,14 @@ import java.util.logging.Level;
import java.util.logging.Logger; import java.util.logging.Logger;
import nl.uva.sne.drip.Swagger2SpringBoot; import nl.uva.sne.drip.Swagger2SpringBoot;
import nl.uva.sne.drip.commons.utils.Converter; import nl.uva.sne.drip.commons.utils.Converter;
import nl.uva.sne.drip.commons.utils.ToscaHelper;
import nl.uva.sne.drip.configuration.MongoConfig; import nl.uva.sne.drip.configuration.MongoConfig;
import nl.uva.sne.drip.model.tosca.Credential; import nl.uva.sne.drip.model.tosca.Credential;
import org.junit.Assert; import org.junit.Assert;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mock.web.MockMultipartFile; import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.context.web.WebAppConfiguration;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
...@@ -73,6 +77,9 @@ public class ServiceTests { ...@@ -73,6 +77,9 @@ public class ServiceTests {
private WebApplicationContext wac; private WebApplicationContext wac;
private MockMvc mockMvc; private MockMvc mockMvc;
@Value("${sure-tosca.base.path}")
private String sureToscaBasePath;
private static final MongodStarter starter = MongodStarter.getDefaultInstance(); private static final MongodStarter starter = MongodStarter.getDefaultInstance();
private static MongodExecutable _mongodExe; private static MongodExecutable _mongodExe;
private static MongodProcess _mongod; private static MongodProcess _mongod;
...@@ -213,27 +220,43 @@ public class ServiceTests { ...@@ -213,27 +220,43 @@ public class ServiceTests {
*/ */
@Test @Test
public void testToscaTemplateServiceDeleteByID() { public void testToscaTemplateServiceDeleteByID() {
try { if (isServiceUp(sureToscaBasePath)) {
Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "deleteByID");
if (toscaTemplateID == null) {
testToscaTemplateServiceSaveFile();
}
toscaTemplateService.deleteByID(toscaTemplateID);
String id = toscaTemplateService.findByID(toscaTemplateID);
} catch (Exception ex) {
if (!(ex instanceof NoSuchElementException)) {
fail(ex.getMessage());
Logger.getLogger(ServiceTests.class.getName()).log(Level.SEVERE, null, ex);
}
} finally {
try { try {
testToscaTemplateServiceSaveFile(); Logger.getLogger(ServiceTests.class.getName()).log(Level.INFO, "deleteByID");
if (toscaTemplateID == null) {
testToscaTemplateServiceSaveFile();
}
toscaTemplateService.deleteByID(toscaTemplateID);
String id = toscaTemplateService.findByID(toscaTemplateID);
} catch (Exception ex) { } catch (Exception ex) {
fail(ex.getMessage()); if (!(ex instanceof NoSuchElementException)) {
Logger.getLogger(ServiceTests.class.getName()).log(Level.SEVERE, null, ex); fail(ex.getMessage());
Logger.getLogger(ServiceTests.class.getName()).log(Level.SEVERE, null, ex);
}
} finally {
try {
testToscaTemplateServiceSaveFile();
} catch (Exception ex) {
fail(ex.getMessage());
Logger.getLogger(ServiceTests.class.getName()).log(Level.SEVERE, null, ex);
}
} }
} }
}
public static Boolean isServiceUp(String serviceBasePath) {
try {
URL serviceUrl = new URL(serviceBasePath);
HttpURLConnection connection = (HttpURLConnection) serviceUrl.openConnection();
//Set request to header to reduce load as Subirkumarsao said.
connection.setRequestMethod("HEAD");
int code = connection.getResponseCode();
} catch (IOException ex) {
return false;
}
return true;
} }
/** /**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment