@Test public void testTemplateInstanceLang() throws Exception { Class<UpdateTemplateInstanceLang> class1 = UpdateTemplateInstanceLang.class; Field field = class1.getDeclaredField("updateTemplateInstance"); field.setAccessible(true); UserId userId = mock(UserId.class); String nodeName = new String("nodename"); String nodeType = new String("nodetype"); LinkedHashMap<String, LinkedHashMap<String,String>> propertyList = new LinkedHashMap<String, LinkedHashMap<String, String>>(); LinkedHashMap<String, String> values = new LinkedHashMap<String, String>(); Map map = mock(Map.class); UpdateTemplateInstance updateTemplateInstance = mock(UpdateTemplateInstance.class); String parameterName = new String("parameterName"); propertyList.put(parameterName, values); values.put("string", NEMOConstants.string); field.set(updateTemplateInstanceLang, updateTemplateInstance); when(tenantManage.getTemplateInstance(userId)) .thenReturn(map) .thenReturn(map) .thenReturn(null); when(tenantManage.getObjectId(userId, nodeName)).thenReturn("11111111-1111-1111-1111-111111111111"); when(map.containsKey(any(TemplateInstanceId.class))) .thenReturn(true) .thenReturn(false); Assert.assertTrue(updateTemplateInstanceLang.templateInstanceLang(userId, nodeName, nodeType, propertyList).equals("The instance " + nodeName + " has exist.")); verify(tenantManage,times(2)).getTemplateInstance(userId); Assert.assertTrue(propertyList.get(parameterName) == values); when(updateTemplateInstance.checkTemplateInstance(any(UserId.class), any(TemplateInstance.class))) .thenReturn(null) .thenReturn("int") .thenReturn("range"); doNothing().when(tenantManage).setUserTemplateInstance(any(UserId.class), any(TemplateInstanceId.class), any(TemplateInstance.class)); Assert.assertTrue(updateTemplateInstanceLang.templateInstanceLang(userId, nodeName, nodeType, propertyList) == null); values.clear(); values.put("11", NEMOConstants.integer); Assert.assertTrue(updateTemplateInstanceLang.templateInstanceLang(userId, nodeName, nodeType, propertyList).equals("int")); values.clear(); values.put("1,1", NEMOConstants.range); Assert.assertTrue(updateTemplateInstanceLang.templateInstanceLang(userId, nodeName, nodeType, propertyList).equals("range")); verify(updateTemplateInstance,times(3)).checkTemplateInstance(any(UserId.class), any(TemplateInstance.class)); }
public String templateInstanceLang(UserId userId, String nodeName, String nodeType, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList){ Boolean instanceExist = false; if (tenantManage.getTemplateInstance(userId)!=null){ String objectId = tenantManage.getObjectId(userId,nodeName); if (tenantManage.getTemplateInstance(userId).containsKey(new TemplateInstanceId(objectId))){ instanceExist = true; } } if (!instanceExist){ TemplateInstanceBuilder instanceBuilder = new TemplateInstanceBuilder(); TemplateInstanceId templateInstanceId = new TemplateInstanceId(UUID.randomUUID().toString()); instanceBuilder.setKey(new TemplateInstanceKey(templateInstanceId)) .setTemplateInstanceId(templateInstanceId) .setTemplateInstanceName(new TemplateInstanceName(nodeName)) .setTemplateName(new TemplateName(nodeType)); if (!propertyList.isEmpty()){ List<TemplateParameter> templateParameterList = new LinkedList<TemplateParameter>(); for (String parameterName : propertyList.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(parameterName))) .setParameterName(new ParameterName(parameterName)); Map<String, String> values = propertyList.get(parameterName); ParameterValuesBuilder valuesBuilder = new ParameterValuesBuilder(); List<StringValue> stringValues = new LinkedList<StringValue>(); List<IntValue> intValues = new LinkedList<IntValue>(); RangeValue rangeValue = null; Long order = 0L; for (String value : values.keySet()){ if (values.get(value).equals(NEMOConstants.string)){ StringValueBuilder stringValueBuilder = new StringValueBuilder(); stringValueBuilder.setKey(new StringValueKey(order,value)) .setValue(value) .setOrder(order); order++; stringValues.add(stringValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.integer)){ IntValueBuilder intValueBuilder = new IntValueBuilder(); intValueBuilder.setKey(new IntValueKey(order,Long.parseLong(value))) .setOrder(Long.parseLong(value)) .setOrder(order); order++; intValues.add(intValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.range)){ RangeValueBuilder rangeValueBuilder = new RangeValueBuilder(); String[] range = value.split(","); rangeValueBuilder.setMax(Long.parseLong(range[0])>Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])) .setMin(Long.parseLong(range[0])<Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])); order++; rangeValue = rangeValueBuilder.build(); } } if ((!stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue==null) ||(stringValues.isEmpty()&&!intValues.isEmpty()&&rangeValue==null) ||stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue!=null){ valuesBuilder.setStringValue(stringValues.isEmpty()?null:stringValues) .setIntValue(intValues.isEmpty()?null:intValues) .setRangeValue(rangeValue); parameterBuilder.setParameterValues(valuesBuilder.build()); }else { return "The value types are not consistent."; } templateParameterList.add(parameterBuilder.build()); } instanceBuilder.setTemplateParameter(templateParameterList); } String errorInfo = updateTemplateInstance.checkTemplateInstance(userId,instanceBuilder.build()); if (errorInfo!=null){ return errorInfo; } else { tenantManage.setUserTemplateInstance(userId,instanceBuilder.getTemplateInstanceId(),instanceBuilder.build()); } } else { return "The instance " + nodeName + " has exist."; } return null; }
UpdateTemplateInstanceLang { public String templateInstanceLang(UserId userId, String nodeName, String nodeType, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList){ Boolean instanceExist = false; if (tenantManage.getTemplateInstance(userId)!=null){ String objectId = tenantManage.getObjectId(userId,nodeName); if (tenantManage.getTemplateInstance(userId).containsKey(new TemplateInstanceId(objectId))){ instanceExist = true; } } if (!instanceExist){ TemplateInstanceBuilder instanceBuilder = new TemplateInstanceBuilder(); TemplateInstanceId templateInstanceId = new TemplateInstanceId(UUID.randomUUID().toString()); instanceBuilder.setKey(new TemplateInstanceKey(templateInstanceId)) .setTemplateInstanceId(templateInstanceId) .setTemplateInstanceName(new TemplateInstanceName(nodeName)) .setTemplateName(new TemplateName(nodeType)); if (!propertyList.isEmpty()){ List<TemplateParameter> templateParameterList = new LinkedList<TemplateParameter>(); for (String parameterName : propertyList.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(parameterName))) .setParameterName(new ParameterName(parameterName)); Map<String, String> values = propertyList.get(parameterName); ParameterValuesBuilder valuesBuilder = new ParameterValuesBuilder(); List<StringValue> stringValues = new LinkedList<StringValue>(); List<IntValue> intValues = new LinkedList<IntValue>(); RangeValue rangeValue = null; Long order = 0L; for (String value : values.keySet()){ if (values.get(value).equals(NEMOConstants.string)){ StringValueBuilder stringValueBuilder = new StringValueBuilder(); stringValueBuilder.setKey(new StringValueKey(order,value)) .setValue(value) .setOrder(order); order++; stringValues.add(stringValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.integer)){ IntValueBuilder intValueBuilder = new IntValueBuilder(); intValueBuilder.setKey(new IntValueKey(order,Long.parseLong(value))) .setOrder(Long.parseLong(value)) .setOrder(order); order++; intValues.add(intValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.range)){ RangeValueBuilder rangeValueBuilder = new RangeValueBuilder(); String[] range = value.split(","); rangeValueBuilder.setMax(Long.parseLong(range[0])>Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])) .setMin(Long.parseLong(range[0])<Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])); order++; rangeValue = rangeValueBuilder.build(); } } if ((!stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue==null) ||(stringValues.isEmpty()&&!intValues.isEmpty()&&rangeValue==null) ||stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue!=null){ valuesBuilder.setStringValue(stringValues.isEmpty()?null:stringValues) .setIntValue(intValues.isEmpty()?null:intValues) .setRangeValue(rangeValue); parameterBuilder.setParameterValues(valuesBuilder.build()); }else { return "The value types are not consistent."; } templateParameterList.add(parameterBuilder.build()); } instanceBuilder.setTemplateParameter(templateParameterList); } String errorInfo = updateTemplateInstance.checkTemplateInstance(userId,instanceBuilder.build()); if (errorInfo!=null){ return errorInfo; } else { tenantManage.setUserTemplateInstance(userId,instanceBuilder.getTemplateInstanceId(),instanceBuilder.build()); } } else { return "The instance " + nodeName + " has exist."; } return null; } }
UpdateTemplateInstanceLang { public String templateInstanceLang(UserId userId, String nodeName, String nodeType, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList){ Boolean instanceExist = false; if (tenantManage.getTemplateInstance(userId)!=null){ String objectId = tenantManage.getObjectId(userId,nodeName); if (tenantManage.getTemplateInstance(userId).containsKey(new TemplateInstanceId(objectId))){ instanceExist = true; } } if (!instanceExist){ TemplateInstanceBuilder instanceBuilder = new TemplateInstanceBuilder(); TemplateInstanceId templateInstanceId = new TemplateInstanceId(UUID.randomUUID().toString()); instanceBuilder.setKey(new TemplateInstanceKey(templateInstanceId)) .setTemplateInstanceId(templateInstanceId) .setTemplateInstanceName(new TemplateInstanceName(nodeName)) .setTemplateName(new TemplateName(nodeType)); if (!propertyList.isEmpty()){ List<TemplateParameter> templateParameterList = new LinkedList<TemplateParameter>(); for (String parameterName : propertyList.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(parameterName))) .setParameterName(new ParameterName(parameterName)); Map<String, String> values = propertyList.get(parameterName); ParameterValuesBuilder valuesBuilder = new ParameterValuesBuilder(); List<StringValue> stringValues = new LinkedList<StringValue>(); List<IntValue> intValues = new LinkedList<IntValue>(); RangeValue rangeValue = null; Long order = 0L; for (String value : values.keySet()){ if (values.get(value).equals(NEMOConstants.string)){ StringValueBuilder stringValueBuilder = new StringValueBuilder(); stringValueBuilder.setKey(new StringValueKey(order,value)) .setValue(value) .setOrder(order); order++; stringValues.add(stringValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.integer)){ IntValueBuilder intValueBuilder = new IntValueBuilder(); intValueBuilder.setKey(new IntValueKey(order,Long.parseLong(value))) .setOrder(Long.parseLong(value)) .setOrder(order); order++; intValues.add(intValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.range)){ RangeValueBuilder rangeValueBuilder = new RangeValueBuilder(); String[] range = value.split(","); rangeValueBuilder.setMax(Long.parseLong(range[0])>Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])) .setMin(Long.parseLong(range[0])<Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])); order++; rangeValue = rangeValueBuilder.build(); } } if ((!stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue==null) ||(stringValues.isEmpty()&&!intValues.isEmpty()&&rangeValue==null) ||stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue!=null){ valuesBuilder.setStringValue(stringValues.isEmpty()?null:stringValues) .setIntValue(intValues.isEmpty()?null:intValues) .setRangeValue(rangeValue); parameterBuilder.setParameterValues(valuesBuilder.build()); }else { return "The value types are not consistent."; } templateParameterList.add(parameterBuilder.build()); } instanceBuilder.setTemplateParameter(templateParameterList); } String errorInfo = updateTemplateInstance.checkTemplateInstance(userId,instanceBuilder.build()); if (errorInfo!=null){ return errorInfo; } else { tenantManage.setUserTemplateInstance(userId,instanceBuilder.getTemplateInstanceId(),instanceBuilder.build()); } } else { return "The instance " + nodeName + " has exist."; } return null; } UpdateTemplateInstanceLang(DataBroker dataBroker, TenantManage tenantManage); }
UpdateTemplateInstanceLang { public String templateInstanceLang(UserId userId, String nodeName, String nodeType, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList){ Boolean instanceExist = false; if (tenantManage.getTemplateInstance(userId)!=null){ String objectId = tenantManage.getObjectId(userId,nodeName); if (tenantManage.getTemplateInstance(userId).containsKey(new TemplateInstanceId(objectId))){ instanceExist = true; } } if (!instanceExist){ TemplateInstanceBuilder instanceBuilder = new TemplateInstanceBuilder(); TemplateInstanceId templateInstanceId = new TemplateInstanceId(UUID.randomUUID().toString()); instanceBuilder.setKey(new TemplateInstanceKey(templateInstanceId)) .setTemplateInstanceId(templateInstanceId) .setTemplateInstanceName(new TemplateInstanceName(nodeName)) .setTemplateName(new TemplateName(nodeType)); if (!propertyList.isEmpty()){ List<TemplateParameter> templateParameterList = new LinkedList<TemplateParameter>(); for (String parameterName : propertyList.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(parameterName))) .setParameterName(new ParameterName(parameterName)); Map<String, String> values = propertyList.get(parameterName); ParameterValuesBuilder valuesBuilder = new ParameterValuesBuilder(); List<StringValue> stringValues = new LinkedList<StringValue>(); List<IntValue> intValues = new LinkedList<IntValue>(); RangeValue rangeValue = null; Long order = 0L; for (String value : values.keySet()){ if (values.get(value).equals(NEMOConstants.string)){ StringValueBuilder stringValueBuilder = new StringValueBuilder(); stringValueBuilder.setKey(new StringValueKey(order,value)) .setValue(value) .setOrder(order); order++; stringValues.add(stringValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.integer)){ IntValueBuilder intValueBuilder = new IntValueBuilder(); intValueBuilder.setKey(new IntValueKey(order,Long.parseLong(value))) .setOrder(Long.parseLong(value)) .setOrder(order); order++; intValues.add(intValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.range)){ RangeValueBuilder rangeValueBuilder = new RangeValueBuilder(); String[] range = value.split(","); rangeValueBuilder.setMax(Long.parseLong(range[0])>Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])) .setMin(Long.parseLong(range[0])<Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])); order++; rangeValue = rangeValueBuilder.build(); } } if ((!stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue==null) ||(stringValues.isEmpty()&&!intValues.isEmpty()&&rangeValue==null) ||stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue!=null){ valuesBuilder.setStringValue(stringValues.isEmpty()?null:stringValues) .setIntValue(intValues.isEmpty()?null:intValues) .setRangeValue(rangeValue); parameterBuilder.setParameterValues(valuesBuilder.build()); }else { return "The value types are not consistent."; } templateParameterList.add(parameterBuilder.build()); } instanceBuilder.setTemplateParameter(templateParameterList); } String errorInfo = updateTemplateInstance.checkTemplateInstance(userId,instanceBuilder.build()); if (errorInfo!=null){ return errorInfo; } else { tenantManage.setUserTemplateInstance(userId,instanceBuilder.getTemplateInstanceId(),instanceBuilder.build()); } } else { return "The instance " + nodeName + " has exist."; } return null; } UpdateTemplateInstanceLang(DataBroker dataBroker, TenantManage tenantManage); String templateInstanceLang(UserId userId, String nodeName, String nodeType, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList); }
UpdateTemplateInstanceLang { public String templateInstanceLang(UserId userId, String nodeName, String nodeType, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList){ Boolean instanceExist = false; if (tenantManage.getTemplateInstance(userId)!=null){ String objectId = tenantManage.getObjectId(userId,nodeName); if (tenantManage.getTemplateInstance(userId).containsKey(new TemplateInstanceId(objectId))){ instanceExist = true; } } if (!instanceExist){ TemplateInstanceBuilder instanceBuilder = new TemplateInstanceBuilder(); TemplateInstanceId templateInstanceId = new TemplateInstanceId(UUID.randomUUID().toString()); instanceBuilder.setKey(new TemplateInstanceKey(templateInstanceId)) .setTemplateInstanceId(templateInstanceId) .setTemplateInstanceName(new TemplateInstanceName(nodeName)) .setTemplateName(new TemplateName(nodeType)); if (!propertyList.isEmpty()){ List<TemplateParameter> templateParameterList = new LinkedList<TemplateParameter>(); for (String parameterName : propertyList.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(parameterName))) .setParameterName(new ParameterName(parameterName)); Map<String, String> values = propertyList.get(parameterName); ParameterValuesBuilder valuesBuilder = new ParameterValuesBuilder(); List<StringValue> stringValues = new LinkedList<StringValue>(); List<IntValue> intValues = new LinkedList<IntValue>(); RangeValue rangeValue = null; Long order = 0L; for (String value : values.keySet()){ if (values.get(value).equals(NEMOConstants.string)){ StringValueBuilder stringValueBuilder = new StringValueBuilder(); stringValueBuilder.setKey(new StringValueKey(order,value)) .setValue(value) .setOrder(order); order++; stringValues.add(stringValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.integer)){ IntValueBuilder intValueBuilder = new IntValueBuilder(); intValueBuilder.setKey(new IntValueKey(order,Long.parseLong(value))) .setOrder(Long.parseLong(value)) .setOrder(order); order++; intValues.add(intValueBuilder.build()); } if (values.get(value).equals(NEMOConstants.range)){ RangeValueBuilder rangeValueBuilder = new RangeValueBuilder(); String[] range = value.split(","); rangeValueBuilder.setMax(Long.parseLong(range[0])>Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])) .setMin(Long.parseLong(range[0])<Long.parseLong(range[1])?Long.parseLong(range[0]):Long.parseLong(range[1])); order++; rangeValue = rangeValueBuilder.build(); } } if ((!stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue==null) ||(stringValues.isEmpty()&&!intValues.isEmpty()&&rangeValue==null) ||stringValues.isEmpty()&&intValues.isEmpty()&&rangeValue!=null){ valuesBuilder.setStringValue(stringValues.isEmpty()?null:stringValues) .setIntValue(intValues.isEmpty()?null:intValues) .setRangeValue(rangeValue); parameterBuilder.setParameterValues(valuesBuilder.build()); }else { return "The value types are not consistent."; } templateParameterList.add(parameterBuilder.build()); } instanceBuilder.setTemplateParameter(templateParameterList); } String errorInfo = updateTemplateInstance.checkTemplateInstance(userId,instanceBuilder.build()); if (errorInfo!=null){ return errorInfo; } else { tenantManage.setUserTemplateInstance(userId,instanceBuilder.getTemplateInstanceId(),instanceBuilder.build()); } } else { return "The instance " + nodeName + " has exist."; } return null; } UpdateTemplateInstanceLang(DataBroker dataBroker, TenantManage tenantManage); String templateInstanceLang(UserId userId, String nodeName, String nodeType, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList);  }