TackerManager implements SfcVnfManager, AutoCloseable { @Override public boolean createSf(ServiceFunctionType sfType) { Token authToken = getToken(); if (authToken == null) { LOG.error("Failed to Acquire Authentication token!"); return false; } WebResource webResource = client.resource(baseUri + ":" + tackerPort).path("/v1.0/vnfs"); TackerRequest tackerRequest = TackerRequest.builder() .setVnf(Vnf.builder() .setName(sfType.getType().getValue()) .setAttributes(Attributes.builder().setServiceType(sfType.getType().getValue()).build()) .build()) .build(); ClientResponse response = (webResource.type(javax.ws.rs.core.MediaType.APPLICATION_JSON) .header("X-Auth-Token", authToken.getId()) .header("X-Auth-Project-Id", authToken.getTenant().getName())).post(ClientResponse.class, GSON.toJson(tackerRequest)); if (response != null) { switch (response.getStatus()) { case 201: String json = response.getEntity(String.class); TackerResponse tackerResponse = GSON.fromJson(json, TackerResponse.class); LOG.info("VNF successfully created."); LOG.debug(GSON.toJson(tackerResponse)); return true; case 401: LOG.debug("Unauthorized! Wrong username or password."); break; default: TackerError error = GSON.fromJson(response.getEntity(String.class), TackerError.class); LOG.debug(error.toString()); break; } } return false; } private  TackerManager(TackerManagerBuilder builder); @Override boolean createSf(ServiceFunctionType sfType); @Override boolean deleteSf(ServiceFunction sf); @Override StatisticByTimestamp getSfStatistics(ServiceFunction sf); @Override void close(); static TackerManagerBuilder builder();  }
@Test public void createSfTest() { ServiceFunctionType sfType = new ServiceFunctionTypeBuilder().setType(new SftTypeName("firewall")).build(); boolean result = tackerManager.createSf(sfType); LOG.debug("Create vnf passed: " + result); Assert.assertTrue(result); ServiceFunction sf = new ServiceFunctionBuilder().setName(new SfName(sfType.getType().getValue())) .setType(sfType.getType()) .build(); result = tackerManager.deleteSf(sf); LOG.debug("Delete vnf passed: " + result); Assert.assertTrue(result); }
@Test public void createSfTestEmptyNameFail() { ServiceFunctionType sfType = new ServiceFunctionTypeBuilder().setType(new SftTypeName("")).build(); boolean result = tackerManager.createSf(sfType); LOG.debug("createSfTestEmptyNameFail passed: " + !result); Assert.assertFalse(result); }