diff --git a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java index 5ac29c4824df..bade9a8a2288 100644 --- a/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java +++ b/web/src/main/java/com/navercorp/pinpoint/web/applicationmap/ServerBuilder.java @@ -37,11 +37,17 @@ public class ServerBuilder { private final AgentHistogramList agentHistogramList; private final Set agentSet; - private MatcherGroup matcherGroup = null; + private final MatcherGroup matcherGroup; + + public ServerBuilder() { + // TODO FIX + this(null); + } public ServerBuilder(MatcherGroup matcherGroup) { this.agentHistogramList = new AgentHistogramList(); this.agentSet = new HashSet(); + // TODO avoid null this.matcherGroup = matcherGroup; } diff --git a/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java new file mode 100644 index 000000000000..a9b22e41623d --- /dev/null +++ b/web/src/test/java/com/navercorp/pinpoint/web/applicationmap/ServerInstanceListTest.java @@ -0,0 +1,68 @@ +/* + * Copyright 2014 NAVER Corp. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.navercorp.pinpoint.web.applicationmap; + +import com.navercorp.pinpoint.common.bo.AgentInfoBo; +import com.navercorp.pinpoint.common.trace.ServiceType; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import static org.junit.Assert.*; + +/** + * @author emeroad + */ +public class ServerInstanceListTest { + + @Test + public void testGetAgentIdList() throws Exception { + + AgentInfoBo agentInfoBo1 = createAgentInfo("agentId1", "testHost"); + AgentInfoBo agentInfoBo2 = createAgentInfo("agentId2", "testHost"); + + Set agentInfoBoSet = new HashSet(); + agentInfoBoSet.add(agentInfoBo1); + agentInfoBoSet.add(agentInfoBo2); + + ServerBuilder builder = new ServerBuilder(); + builder.addAgentInfo(agentInfoBoSet); + ServerInstanceList serverInstanceList = builder.build(); + List agentIdList = serverInstanceList.getAgentIdList(); + + Assert.assertEquals(agentIdList.size(), 2); + Assert.assertEquals(agentIdList.get(0), "agentId1"); + Assert.assertEquals(agentIdList.get(1), "agentId2"); + } + + public static AgentInfoBo createAgentInfo(String agentId, String hostName) { + AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder(); + agentInfoBuilder.setAgentId(agentId); + + ServiceType serviceType = ServiceType.TEST_STAND_ALONE; + agentInfoBuilder.setServiceTypeCode(serviceType.getCode()); + // TODO FIX api + agentInfoBuilder.setServiceType(serviceType); + + agentInfoBuilder.setHostName(hostName); + + return agentInfoBuilder.build(); + } +} \ No newline at end of file diff --git a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java index d4e630242d36..c8f23b77e289 100644 --- a/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java +++ b/web/src/test/java/com/navercorp/pinpoint/web/view/ServerInstanceListSerializerTest.java @@ -16,18 +16,18 @@ package com.navercorp.pinpoint.web.view; -import com.navercorp.pinpoint.common.ServiceType; -import com.navercorp.pinpoint.common.bo.AgentInfoBo; -import com.navercorp.pinpoint.web.applicationmap.ServerBuilder; -import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList; +import java.util.HashSet; -import org.codehaus.jackson.map.ObjectMapper; -import org.codehaus.jackson.map.ObjectWriter; +import com.navercorp.pinpoint.web.applicationmap.ServerInstanceListTest; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashSet; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectWriter; +import com.navercorp.pinpoint.common.bo.AgentInfoBo; +import com.navercorp.pinpoint.web.applicationmap.ServerBuilder; +import com.navercorp.pinpoint.web.applicationmap.ServerInstanceList; /** * @author emeroad @@ -39,18 +39,15 @@ public class ServerInstanceListSerializerTest { @Test public void testSerialize() throws Exception { - AgentInfoBo.Builder agentInfoBuilder = new AgentInfoBo.Builder(); - agentInfoBuilder.agentId("agentId"); - agentInfoBuilder.serviceType(ServiceType.TOMCAT); - agentInfoBuilder.hostName("testcomputer"); + AgentInfoBo agentInfoBo = ServerInstanceListTest.createAgentInfo("agentId1", "testHost"); - AgentInfoBo agentInfoBo = agentInfoBuilder.build(); + HashSet agentInfoBoSet = new HashSet(); + agentInfoBoSet.add(agentInfoBo); - HashSet set = new HashSet(); - set.add(agentInfoBo); ServerBuilder builder = new ServerBuilder(null); - builder.addAgentInfo(set); + builder.addAgentInfo(agentInfoBoSet); + ServerInstanceList serverInstanceList = builder.build(); ObjectWriter objectWriter = mapper.writerWithDefaultPrettyPrinter(); String json = objectWriter.writeValueAsString(serverInstanceList);