BackendUtils { public static TTopologyTemplate updateVersionOfNodeTemplate(TTopologyTemplate topologyTemplate, String nodeTemplateId, String newComponentType) { topologyTemplate.getNodeTemplateOrRelationshipTemplate().stream() .filter(template -> template.getId().equals(nodeTemplateId)) .findFirst() .ifPresent(template -> template.setType(newComponentType)); return topologyTemplate; }  static boolean isFileNewerThanModifiedDate(long millis, String modified); static T getDefinitionsChildId(Class<T> idClass, String qnameStr); static T getDefinitionsChildId(Class<T> idClass, QName qname); static T getDefinitionsChildId(Class<T> idClass, String namespace, String id, boolean URLencoded); static Namespace getNamespace(ToscaElementId id); static String getDefinitionsAsXMLString(TDefinitions definitions); static String getName(DefinitionsChildId instanceId); static String getPathInsideRepo(GenericId id); static String getPathInsideRepo(RepositoryFileReference ref); static String getFilenameAndSubDirectory(RepositoryFileReference ref); static RepositoryFileReference getRefOfDefinitions(DefinitionsChildId id); static String getFileNameOfDefinitions(DefinitionsChildId id); static String getFileNameOfDefinitions(Class<T> id); static String getTypeForAdminId(Class<? extends AdminId> idClass); static RepositoryFileReference getRefOfConfiguration(GenericId id); static RepositoryFileReference getRefOfJsonConfiguration(GenericId id); static List<TNodeTemplate> getAllNestedNodeTemplates(TServiceTemplate serviceTemplate); static Collection<QName> getArtifactTemplatesOfReferencedDeploymentArtifacts(TNodeTemplate nodeTemplate); static Collection<QName> getArtifactTemplatesOfReferencedImplementationArtifacts(TNodeTemplate nodeTemplate); static Definitions updateWrapperDefinitions(DefinitionsChildId tcId, Definitions defs); static TTopologyTemplate clone(TTopologyTemplate topologyTemplate); static TNodeTemplate clone(TNodeTemplate nodeTemplate); static TRelationshipTemplate clone(TRelationshipTemplate relationshipTemplate); static Definitions createWrapperDefinitions(DefinitionsChildId tcId); static Definitions createWrapperDefinitionsAndInitialEmptyElement(IRepository repository, DefinitionsChildId id); static void initializeProperties(IRepository repository, TEntityTemplate entityTemplate); static void persist(IRepository repository, DefinitionsChildId id, TExtensibleElements element); static void persist(DefinitionsChildId id, Definitions definitions); static void persist(Object o, RepositoryFileReference ref, MediaType mediaType); static Optional<XSModel> getXSModel(final RepositoryFileReference ref); static void deriveWPD(TEntityType ci, List<String> errors); SortedSet<T> getAllTOSCAElementIds(Class<T> idClass); static Collection<QName> convertDefinitionsChildIdCollectionToQNameCollection(Collection<? extends DefinitionsChildId> col); static MediaType getMimeType(BufferedInputStream bis, String fn); static MediaType getFixedMimeType(BufferedInputStream is, String fileName, MediaType mediaType); static void copyIdToFields(HasIdInIdOrNameField element, DefinitionsChildId id); static GitInfo getGitInformation(DirectoryId directoryId); static TArtifactTemplate getTArtifactTemplate(DirectoryId directoryId); static DirectoryId getYamlArtifactsDirectoryOfNodeTemplate(ServiceTemplateId serviceTemplateId, String nodeTemplateId); static DirectoryId getYamlArtifactDirectoryOfNodeTemplate(ServiceTemplateId serviceTemplateId,
                                                                     String nodeTemplateId, String yamlArtifactId); static boolean isGlobMatch(String glob, Path path); static boolean injectArtifactTemplateIntoDeploymentArtifact(ServiceTemplateId serviceTemplate, String nodeTemplateId, String deploymentArtifactId, ArtifactTemplateId artifactTemplate); static String getImportLocationForWinerysPropertiesDefinitionXSD(EntityTypeId tcId, URI uri, String wrapperElementLocalName); static TArtifactTemplate synchronizeReferences(IRepository repository, ArtifactTemplateId id); static void synchronizeReferences(ServiceTemplateId id); static String getXMLAsString(Object obj); static String getXMLAsString(T obj, boolean includeProcessingInstruction); static String getXMLAsString(Class<T> clazz, T obj, boolean includeProcessingInstruction); static ErrorHandler getErrorHandler(StringBuilder sb); static RepositoryFileReference getRepositoryFileReference(Path rootPath, Path path, DirectoryId directoryId); static void importDirectory(Path rootPath, IRepository repository, DirectoryId dir); static Definitions getDefinitionsHavingCorrectImports(IRepository repository, DefinitionsChildId id); static void mergeTopologyTemplateAinTopologyTemplateB(ServiceTemplateId serviceTemplateIdA, ServiceTemplateId serviceTemplateIdB); static Map<String, String> mergeTopologyTemplateAinTopologyTemplateB(TTopologyTemplate topologyTemplateA, TTopologyTemplate topologyTemplateB); static Map<String, String> mergeTopologyTemplateAinTopologyTemplateB(TTopologyTemplate topologyTemplateA, TTopologyTemplate topologyTemplateB, List<TEntityTemplate> stayingElements); static TTopologyTemplate updateVersionOfNodeTemplate(TTopologyTemplate topologyTemplate, String nodeTemplateId, String newComponentType); static SortedSet<? extends DefinitionsChildId> getOtherVersionDefinitionsFromDefinition(DefinitionsChildId id); static List<WineryVersion> getAllVersionsOfOneDefinition(DefinitionsChildId id); static WineryVersion getCurrentVersionWithAllFlags(DefinitionsChildId id); static WineryVersion getPredecessor(DefinitionsChildId id); static ToscaDiff compare(DefinitionsChildId id, WineryVersion versionToCompareTo); static void commit(DefinitionsChildId componentToCommit, String commitMessagePrefix);  }
@Test public void testUpdateVersionOfNodeTemplate() throws Exception { TTopologyTemplate topologyTemplate = new TTopologyTemplate(); TNodeTemplate nt1 = new TNodeTemplate(); TNodeTemplate nt2 = new TNodeTemplate(); nt1.setId("java8_1.0-w1-wip1_3"); nt1.setType(new QName("namespace", "java8_1.0-w1-wip1")); nt2.setId("java8_1.0-w2-wip2"); nt2.setType(new QName("namespace", "java8_1.0-w2-wip2")); List<TEntityTemplate> entityTemplates = topologyTemplate.getNodeTemplateOrRelationshipTemplate(); entityTemplates.add(nt1); TTopologyTemplate resultTopologyTemplate = BackendUtils.updateVersionOfNodeTemplate(topologyTemplate, "java8_1.0-w1-wip1_3", "{namespace}java8_1.0-w2-wip2"); List<TEntityTemplate> entityTemplatesClone = resultTopologyTemplate.getNodeTemplateOrRelationshipTemplate(); assertEquals(entityTemplates.get(0).getTypeAsQName().toString(), "{namespace}java8_1.0-w2-wip2"); }