@Test public void testTemplateDefinitionLang() throws Exception { UserId userId = mock(UserId.class); NodeName nodeName = mock(NodeName.class); AbstractNode abstractNode = mock(AbstractNode.class); ConnectionName connectionName = mock(ConnectionName.class); AbstractConnection abstractConnection = mock(AbstractConnection.class); FlowName flowName = mock(FlowName.class); AbstractFlow abstractFlow = mock(AbstractFlow.class); OperationName operationName = mock(OperationName.class); AbstractOperation abstractOperation = mock(AbstractOperation.class); UpdateTemplateDefinition updateTemplateDefinition = mock(UpdateTemplateDefinition.class); String templateName = new String("test"); String value = new String("string"); LinkedHashMap<String, String> parameters = new LinkedHashMap<String, String>(); Map<NodeName, AbstractNode> abstractNodes = new HashMap<NodeName, AbstractNode>(); Map<ConnectionName, AbstractConnection> abstractConnections = new HashMap<ConnectionName, AbstractConnection>(); Map<FlowName, AbstractFlow> abstractFlows = new HashMap<FlowName, AbstractFlow>(); Map<OperationName, AbstractOperation> abstractOperations = new HashMap<OperationName, AbstractOperation>(); parameters.put(value, NEMOConstants.string); abstractConnections.put(connectionName,abstractConnection); abstractNodes.put(nodeName, abstractNode); abstractFlows.put(flowName,abstractFlow); abstractOperations.put(operationName,abstractOperation); field_definition.set(updateTemplateDefinitionLang, updateTemplateDefinition); when(updateTemplateDefinition.checkTemplateDefinition(any(UserId.class),any(TemplateDefinition.class))) .thenReturn("1") .thenReturn("2") .thenReturn("3"); Assert.assertTrue(updateTemplateDefinitionLang.templateDefinitionLang(userId, templateName, parameters).equals("1")); parameters.clear(); parameters.put(value, NEMOConstants.integer); field_abstractNodes.set(updateTemplateDefinitionLang, abstractNodes); field_abstractConnections.set(updateTemplateDefinitionLang, abstractConnections); field_abstractFlows.set(updateTemplateDefinitionLang,abstractFlows); field_abstractOperations.set(updateTemplateDefinitionLang,abstractOperations); Assert.assertTrue(updateTemplateDefinitionLang.templateDefinitionLang(userId, templateName, parameters).equals("2")); parameters.clear(); parameters.put(value, NEMOConstants.range); Assert.assertTrue(updateTemplateDefinitionLang.templateDefinitionLang(userId, templateName, parameters).equals("3")); verify(updateTemplateDefinition,times(3)).checkTemplateDefinition(any(UserId.class),any(TemplateDefinition.class)); }
public String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters){ TemplateDefinitionBuilder builder = new TemplateDefinitionBuilder(); builder.setKey(new TemplateDefinitionKey(new TemplateName(templateName))) .setTemplateName(new TemplateName(templateName)); List<TemplateParameter> templateParameters = new LinkedList<TemplateParameter>(); for (String value : parameters.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(value))) .setParameterName(new ParameterName(value)); if (parameters.get(value).equals(NEMOConstants.string)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.String); } else if (parameters.get(value).equals(NEMOConstants.integer)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Int); } else if (parameters.get(value).equals(NEMOConstants.range)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Range); } templateParameters.add(parameterBuilder.build()); } builder.setTemplateParameter(templateParameters); AbstractIntentsBuilder intentsBuilder = new AbstractIntentsBuilder(); AbstractObjectsBuilder objectsBuilder = new AbstractObjectsBuilder(); if (!abstractNodes.isEmpty()){ List<AbstractNode> abstractNodeList = new LinkedList<AbstractNode>(); for (AbstractNode node : abstractNodes.values()){ abstractNodeList.add(node); } objectsBuilder.setAbstractNode(abstractNodeList); }else { objectsBuilder.setAbstractNode(null); } if (!abstractConnections.isEmpty()){ List<AbstractConnection> abstractConnectionList = new LinkedList<AbstractConnection>(); for (AbstractConnection connection : abstractConnections.values()){ abstractConnectionList.add(connection); } objectsBuilder.setAbstractConnection(abstractConnectionList); }else { objectsBuilder.setAbstractConnection(null); } if (!abstractFlows.isEmpty()){ List<AbstractFlow> abstractFlowList = new ArrayList<AbstractFlow>(); for (AbstractFlow flow : abstractFlows.values()){ abstractFlowList.add(flow); } objectsBuilder.setAbstractFlow(abstractFlowList); }else { objectsBuilder.setAbstractFlow(null); } AbstractOperationsBuilder operationsBuilder = new AbstractOperationsBuilder(); if (!abstractOperations.isEmpty()){ List<AbstractOperation> abstractOperationList = new LinkedList<AbstractOperation>(); for (AbstractOperation operation : abstractOperations.values()){ abstractOperationList.add(operation); } operationsBuilder.setAbstractOperation(abstractOperationList); }else { operationsBuilder.setAbstractOperation(null); } intentsBuilder.setAbstractObjects(objectsBuilder.build()) .setAbstractOperations(operationsBuilder.build()); builder.setAbstractIntents(intentsBuilder.build()); return definition.checkTemplateDefinition(userId,builder.build()); }
UpdateTemplateDefinitionLang { public String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters){ TemplateDefinitionBuilder builder = new TemplateDefinitionBuilder(); builder.setKey(new TemplateDefinitionKey(new TemplateName(templateName))) .setTemplateName(new TemplateName(templateName)); List<TemplateParameter> templateParameters = new LinkedList<TemplateParameter>(); for (String value : parameters.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(value))) .setParameterName(new ParameterName(value)); if (parameters.get(value).equals(NEMOConstants.string)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.String); } else if (parameters.get(value).equals(NEMOConstants.integer)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Int); } else if (parameters.get(value).equals(NEMOConstants.range)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Range); } templateParameters.add(parameterBuilder.build()); } builder.setTemplateParameter(templateParameters); AbstractIntentsBuilder intentsBuilder = new AbstractIntentsBuilder(); AbstractObjectsBuilder objectsBuilder = new AbstractObjectsBuilder(); if (!abstractNodes.isEmpty()){ List<AbstractNode> abstractNodeList = new LinkedList<AbstractNode>(); for (AbstractNode node : abstractNodes.values()){ abstractNodeList.add(node); } objectsBuilder.setAbstractNode(abstractNodeList); }else { objectsBuilder.setAbstractNode(null); } if (!abstractConnections.isEmpty()){ List<AbstractConnection> abstractConnectionList = new LinkedList<AbstractConnection>(); for (AbstractConnection connection : abstractConnections.values()){ abstractConnectionList.add(connection); } objectsBuilder.setAbstractConnection(abstractConnectionList); }else { objectsBuilder.setAbstractConnection(null); } if (!abstractFlows.isEmpty()){ List<AbstractFlow> abstractFlowList = new ArrayList<AbstractFlow>(); for (AbstractFlow flow : abstractFlows.values()){ abstractFlowList.add(flow); } objectsBuilder.setAbstractFlow(abstractFlowList); }else { objectsBuilder.setAbstractFlow(null); } AbstractOperationsBuilder operationsBuilder = new AbstractOperationsBuilder(); if (!abstractOperations.isEmpty()){ List<AbstractOperation> abstractOperationList = new LinkedList<AbstractOperation>(); for (AbstractOperation operation : abstractOperations.values()){ abstractOperationList.add(operation); } operationsBuilder.setAbstractOperation(abstractOperationList); }else { operationsBuilder.setAbstractOperation(null); } intentsBuilder.setAbstractObjects(objectsBuilder.build()) .setAbstractOperations(operationsBuilder.build()); builder.setAbstractIntents(intentsBuilder.build()); return definition.checkTemplateDefinition(userId,builder.build()); } }
UpdateTemplateDefinitionLang { public String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters){ TemplateDefinitionBuilder builder = new TemplateDefinitionBuilder(); builder.setKey(new TemplateDefinitionKey(new TemplateName(templateName))) .setTemplateName(new TemplateName(templateName)); List<TemplateParameter> templateParameters = new LinkedList<TemplateParameter>(); for (String value : parameters.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(value))) .setParameterName(new ParameterName(value)); if (parameters.get(value).equals(NEMOConstants.string)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.String); } else if (parameters.get(value).equals(NEMOConstants.integer)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Int); } else if (parameters.get(value).equals(NEMOConstants.range)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Range); } templateParameters.add(parameterBuilder.build()); } builder.setTemplateParameter(templateParameters); AbstractIntentsBuilder intentsBuilder = new AbstractIntentsBuilder(); AbstractObjectsBuilder objectsBuilder = new AbstractObjectsBuilder(); if (!abstractNodes.isEmpty()){ List<AbstractNode> abstractNodeList = new LinkedList<AbstractNode>(); for (AbstractNode node : abstractNodes.values()){ abstractNodeList.add(node); } objectsBuilder.setAbstractNode(abstractNodeList); }else { objectsBuilder.setAbstractNode(null); } if (!abstractConnections.isEmpty()){ List<AbstractConnection> abstractConnectionList = new LinkedList<AbstractConnection>(); for (AbstractConnection connection : abstractConnections.values()){ abstractConnectionList.add(connection); } objectsBuilder.setAbstractConnection(abstractConnectionList); }else { objectsBuilder.setAbstractConnection(null); } if (!abstractFlows.isEmpty()){ List<AbstractFlow> abstractFlowList = new ArrayList<AbstractFlow>(); for (AbstractFlow flow : abstractFlows.values()){ abstractFlowList.add(flow); } objectsBuilder.setAbstractFlow(abstractFlowList); }else { objectsBuilder.setAbstractFlow(null); } AbstractOperationsBuilder operationsBuilder = new AbstractOperationsBuilder(); if (!abstractOperations.isEmpty()){ List<AbstractOperation> abstractOperationList = new LinkedList<AbstractOperation>(); for (AbstractOperation operation : abstractOperations.values()){ abstractOperationList.add(operation); } operationsBuilder.setAbstractOperation(abstractOperationList); }else { operationsBuilder.setAbstractOperation(null); } intentsBuilder.setAbstractObjects(objectsBuilder.build()) .setAbstractOperations(operationsBuilder.build()); builder.setAbstractIntents(intentsBuilder.build()); return definition.checkTemplateDefinition(userId,builder.build()); } UpdateTemplateDefinitionLang(DataBroker dataBroker, TenantManage tenantManage); }
UpdateTemplateDefinitionLang { public String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters){ TemplateDefinitionBuilder builder = new TemplateDefinitionBuilder(); builder.setKey(new TemplateDefinitionKey(new TemplateName(templateName))) .setTemplateName(new TemplateName(templateName)); List<TemplateParameter> templateParameters = new LinkedList<TemplateParameter>(); for (String value : parameters.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(value))) .setParameterName(new ParameterName(value)); if (parameters.get(value).equals(NEMOConstants.string)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.String); } else if (parameters.get(value).equals(NEMOConstants.integer)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Int); } else if (parameters.get(value).equals(NEMOConstants.range)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Range); } templateParameters.add(parameterBuilder.build()); } builder.setTemplateParameter(templateParameters); AbstractIntentsBuilder intentsBuilder = new AbstractIntentsBuilder(); AbstractObjectsBuilder objectsBuilder = new AbstractObjectsBuilder(); if (!abstractNodes.isEmpty()){ List<AbstractNode> abstractNodeList = new LinkedList<AbstractNode>(); for (AbstractNode node : abstractNodes.values()){ abstractNodeList.add(node); } objectsBuilder.setAbstractNode(abstractNodeList); }else { objectsBuilder.setAbstractNode(null); } if (!abstractConnections.isEmpty()){ List<AbstractConnection> abstractConnectionList = new LinkedList<AbstractConnection>(); for (AbstractConnection connection : abstractConnections.values()){ abstractConnectionList.add(connection); } objectsBuilder.setAbstractConnection(abstractConnectionList); }else { objectsBuilder.setAbstractConnection(null); } if (!abstractFlows.isEmpty()){ List<AbstractFlow> abstractFlowList = new ArrayList<AbstractFlow>(); for (AbstractFlow flow : abstractFlows.values()){ abstractFlowList.add(flow); } objectsBuilder.setAbstractFlow(abstractFlowList); }else { objectsBuilder.setAbstractFlow(null); } AbstractOperationsBuilder operationsBuilder = new AbstractOperationsBuilder(); if (!abstractOperations.isEmpty()){ List<AbstractOperation> abstractOperationList = new LinkedList<AbstractOperation>(); for (AbstractOperation operation : abstractOperations.values()){ abstractOperationList.add(operation); } operationsBuilder.setAbstractOperation(abstractOperationList); }else { operationsBuilder.setAbstractOperation(null); } intentsBuilder.setAbstractObjects(objectsBuilder.build()) .setAbstractOperations(operationsBuilder.build()); builder.setAbstractIntents(intentsBuilder.build()); return definition.checkTemplateDefinition(userId,builder.build()); } UpdateTemplateDefinitionLang(DataBroker dataBroker, TenantManage tenantManage); String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters); String createAbstractNode(String name, String type, List<String> subnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList); String createAbstractConnection(String name, String type, List<String> endnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList); String createAbstractFlow(String name,LinkedHashMap<String,LinkedHashMap<String,String>> matches,LinkedHashMap<String,LinkedHashMap<String,String>> propertyList); String createAbstractOperation(String name, String target, String priority, LinkedHashMap<String,LinkedHashMap<String,String>> conditions,LinkedHashMap<String,LinkedHashMap<String,String>>actions); }
UpdateTemplateDefinitionLang { public String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters){ TemplateDefinitionBuilder builder = new TemplateDefinitionBuilder(); builder.setKey(new TemplateDefinitionKey(new TemplateName(templateName))) .setTemplateName(new TemplateName(templateName)); List<TemplateParameter> templateParameters = new LinkedList<TemplateParameter>(); for (String value : parameters.keySet()){ TemplateParameterBuilder parameterBuilder = new TemplateParameterBuilder(); parameterBuilder.setKey(new TemplateParameterKey(new ParameterName(value))) .setParameterName(new ParameterName(value)); if (parameters.get(value).equals(NEMOConstants.string)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.String); } else if (parameters.get(value).equals(NEMOConstants.integer)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Int); } else if (parameters.get(value).equals(NEMOConstants.range)){ parameterBuilder.setParameterValueType(TemplateParameter.ParameterValueType.Range); } templateParameters.add(parameterBuilder.build()); } builder.setTemplateParameter(templateParameters); AbstractIntentsBuilder intentsBuilder = new AbstractIntentsBuilder(); AbstractObjectsBuilder objectsBuilder = new AbstractObjectsBuilder(); if (!abstractNodes.isEmpty()){ List<AbstractNode> abstractNodeList = new LinkedList<AbstractNode>(); for (AbstractNode node : abstractNodes.values()){ abstractNodeList.add(node); } objectsBuilder.setAbstractNode(abstractNodeList); }else { objectsBuilder.setAbstractNode(null); } if (!abstractConnections.isEmpty()){ List<AbstractConnection> abstractConnectionList = new LinkedList<AbstractConnection>(); for (AbstractConnection connection : abstractConnections.values()){ abstractConnectionList.add(connection); } objectsBuilder.setAbstractConnection(abstractConnectionList); }else { objectsBuilder.setAbstractConnection(null); } if (!abstractFlows.isEmpty()){ List<AbstractFlow> abstractFlowList = new ArrayList<AbstractFlow>(); for (AbstractFlow flow : abstractFlows.values()){ abstractFlowList.add(flow); } objectsBuilder.setAbstractFlow(abstractFlowList); }else { objectsBuilder.setAbstractFlow(null); } AbstractOperationsBuilder operationsBuilder = new AbstractOperationsBuilder(); if (!abstractOperations.isEmpty()){ List<AbstractOperation> abstractOperationList = new LinkedList<AbstractOperation>(); for (AbstractOperation operation : abstractOperations.values()){ abstractOperationList.add(operation); } operationsBuilder.setAbstractOperation(abstractOperationList); }else { operationsBuilder.setAbstractOperation(null); } intentsBuilder.setAbstractObjects(objectsBuilder.build()) .setAbstractOperations(operationsBuilder.build()); builder.setAbstractIntents(intentsBuilder.build()); return definition.checkTemplateDefinition(userId,builder.build()); } UpdateTemplateDefinitionLang(DataBroker dataBroker, TenantManage tenantManage); String templateDefinitionLang(UserId userId, String templateName, LinkedHashMap<String, String> parameters); String createAbstractNode(String name, String type, List<String> subnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList); String createAbstractConnection(String name, String type, List<String> endnodes, LinkedHashMap<String, LinkedHashMap<String,String>> propertyList); String createAbstractFlow(String name,LinkedHashMap<String,LinkedHashMap<String,String>> matches,LinkedHashMap<String,LinkedHashMap<String,String>> propertyList); String createAbstractOperation(String name, String target, String priority, LinkedHashMap<String,LinkedHashMap<String,String>> conditions,LinkedHashMap<String,LinkedHashMap<String,String>>actions);  }