Add UT case for YamlUtil 95/37095/1
authorluxin <luxin7@huawei.com>
Tue, 20 Mar 2018 12:56:44 +0000 (20:56 +0800)
committerluxin <luxin7@huawei.com>
Tue, 20 Mar 2018 12:56:44 +0000 (20:56 +0800)
Change-Id: I04309c693f8f9a2be9085f277e8a9cec1b16a81f
Issue-ID: VFC-833
Signed-off-by: luxin <luxin7@huawei.com>
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/DownloadCsarManagerTest.java
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/java/org/onap/vfc/nfvo/vnfm/gvnfm/jujuvnfmadapter/common/YamlUtilTest.java
juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml [new file with mode: 0644]

index 533e081..75dd4a4 100644 (file)
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 package org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common;
 
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertTrue;
 
 import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
 
+import org.apache.http.HttpResponse;
+import org.apache.http.ProtocolVersion;
+import org.apache.http.StatusLine;
+import org.apache.http.message.BasicHttpResponse;
+import org.apache.http.message.BasicStatusLine;
 import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.DownloadCsarManager;
 
 public class DownloadCsarManagerTest {
+
     DownloadCsarManager mgr;
+
     @Test
     public void test() {
-        String url="";
-        String filepath="";
+        String url = "";
+        String filepath = "";
         mgr.download(url);
         mgr.download(url, filepath);
         mgr.getRandomFileName();
     }
+
     @Test
     public void testPrivateConstructor() throws Exception {
         Constructor constructor = DownloadCsarManager.class.getDeclaredConstructor();
@@ -40,4 +48,35 @@ public class DownloadCsarManagerTest {
         constructor.setAccessible(true);
         constructor.newInstance();
     }
+
+    @Test
+    public void getFileNameTest() {
+        ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1);
+        StatusLine sl = new BasicStatusLine(version, 200, "success");
+        HttpResponse response = new BasicHttpResponse(sl);
+        response.setHeader("Content-Disposition", "filename");
+        DownloadCsarManager.getFileName(response);
+    }
+
+    @Test
+    public void downloadTest() {
+        DownloadCsarManager.download("http://www.baidu.com");
+        DownloadCsarManager.download("http://www.baidu.com", "/opt");
+        DownloadCsarManager.getRandomFileName();
+    }
+
+    @Test
+    public void getFilePath() {
+        ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1);
+        StatusLine sl = new BasicStatusLine(version, 200, "success");
+        HttpResponse response = new BasicHttpResponse(sl);
+        response.setHeader("Content-Disposition", "filename");
+        DownloadCsarManager.getFilePath(response);
+    }
+
+    @Test
+    public void testUnzip() {
+        DownloadCsarManager.unzipCSAR("test.zip", "/opt");
+    }
+
 }
index 7bcbd14..e98f058 100644 (file)
@@ -20,13 +20,13 @@ import java.io.File;
 
 import org.junit.Before;
 import org.junit.Test;
-import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.YamlUtil;
 import org.onap.vfc.nfvo.vnfm.gvnfm.jujuvnfmadapter.common.restclient.ServiceException;
 import org.yaml.snakeyaml.Yaml;
 
 import net.sf.json.JSON;
 
 public class YamlUtilTest {
+
     YamlUtil yaml;
 
     @Before
@@ -38,12 +38,18 @@ public class YamlUtilTest {
     @Test
     public void test() throws ServiceException {
         String yamlName = "src/test/resources/test.yaml";
+        String arrayName = "src/test/resources/testArray.yaml";
+        JSON json = yaml.yamlToJson(yamlName);
+        yaml.yamlToJson(arrayName);
+        String S = yaml.loadYaml(yamlName);
+        Yaml yaml = new Yaml();
+        File file = new File(yamlName);
+    }
 
-        JSON json=yaml.yamlToJson(yamlName);
-
-        String S=yaml.loadYaml(yamlName);
-          Yaml yaml = new Yaml();
-          File file =new File(yamlName);
+    @Test
+    public void testFileNotFoundException() throws ServiceException {
+        yaml.yamlToJson("src/test/resources/abc.yaml");
+        yaml.loadYaml("src/test/resources/abc.yaml");
     }
 
 }
diff --git a/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml b/juju/juju-vnfmadapter/Juju-vnfmadapterService/service/src/test/resources/testArray.yaml
new file mode 100644 (file)
index 0000000..d08d0bd
--- /dev/null
@@ -0,0 +1,3 @@
+- Cat\r
+- Dog\r
+- Goldfish
\ No newline at end of file