### Question:
ServerTemplateConverter { public static ServerTemplate fromState(KieServerState state) { if (state == null) { return null; } if (state.getConfiguration() == null) { throw new IllegalArgumentException("Kie server configuration can not be empty."); } ServerTemplate template = new ServerTemplate(); String id = state.getConfiguration().getConfigItemValue(KIE_SERVER_ID); String name = state.getConfiguration().getConfigItemValue(KIE_SERVER_SERVICES_OPENSHIFT_SERVICE_NAME, id); String mode = state.getConfiguration().getConfigItemValue(KIE_SERVER_MODE, KieServerMode.DEVELOPMENT.name()); Optional<String> urlOpt = resolveServerUrl(state); template.setId(id); template.setName(name); urlOpt.ifPresent(url -> template.addServerInstance(new ServerInstanceKey(id, id, id, url))); for (KieContainerResource conRes : state.getContainers()) { Map<Capability, ContainerConfig> configs = new EnumMap<>(Capability.class); KieScannerResource scanner = conRes.getScanner(); if (scanner != null) { configs.put(Capability.RULE, new RuleConfig(scanner.getPollInterval(), scanner.getStatus())); } ProcessConfig pcfg = null; for (KieServerConfigItem item : conRes.getConfigItems()) { if (CAPABILITY_BPM.equals(item.getType())) { pcfg = pcfg == null ? new ProcessConfig() : pcfg; if (PCFG_KIE_BASE.equals(item.getName())) { pcfg.setKBase(item.getValue()); } if (PCFG_KIE_SESSION.equals(item.getName())) { pcfg.setKSession(item.getValue()); } if (PCFG_MERGE_MODE.equals(item.getName())) { pcfg.setMergeMode(item.getValue()); } if (PCFG_RUNTIME_STRATEGY.equals(item.getName())) { pcfg.setRuntimeStrategy(item.getValue()); } } } if (pcfg != null) { configs.put(Capability.PROCESS, pcfg); } template.addContainerSpec(new ContainerSpec(conRes.getContainerId(), conRes.getContainerAlias(), new ServerTemplateKey(id, id), conRes.getReleaseId(), conRes.getStatus(), configs)); } List<String> capabilities = Stream.of(Capability.values()).map(Capability::name).collect(Collectors.toList()); KieServerConfig kcfg = state.getConfiguration(); if (kcfg.getConfigItem(KIE_JBPM_SERVER_EXT_DISABLED) != null) { capabilities.remove(Capability.PROCESS.name()); } if (kcfg.getConfigItem(KIE_DROOLS_SERVER_EXT_DISABLED) != null) { capabilities.remove(Capability.RULE.name()); } if (kcfg.getConfigItem(KIE_OPTAPLANNER_SERVER_EXT_DISABLED) != null) { capabilities.remove(Capability.PLANNING.name()); } template.setCapabilities(capabilities); template.setMode(KieServerMode.valueOf(mode.toUpperCase())); return template; } private  ServerTemplateConverter(); static ServerTemplate fromState(KieServerState state); static KieServerState toState(ServerTemplate template);  }### Answer:
@Test public void testFromState() { KieServerState state = repo.load(TEST_KIE_SERVER_ID); ServerTemplate template = ServerTemplateConverter.fromState(state); assertTrue(isMatching(template, state)); }
@Test public void testFromStateWithoutServerLocation() { KieServerState state = repo.load(TEST_KIE_SERVER_ID); KieServerConfigItem cfgItem = state.getConfiguration().getConfigItem(KieServerConstants.KIE_SERVER_LOCATION); state.getConfiguration().removeConfigItem(cfgItem); ServerTemplate template = ServerTemplateConverter.fromState(state); assertTrue(isMatching(template, state)); }