Java Code Examples for com.ctrip.framework.apollo.core.ConfigConsts#CLUSTER_NAME_DEFAULT

The following examples show how to use com.ctrip.framework.apollo.core.ConfigConsts#CLUSTER_NAME_DEFAULT . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ReleaseOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenReleaseDTO getLatestActiveRelease(String appId, String env, String clusterName, String namespaceName) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases/latest",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Get latest active release for appId: %s, cluster: %s, namespace: %s in env: %s failed", appId,
            clusterName, namespaceName, env), ex);
  }
}
 
Example 2
Source File: NamespaceOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenNamespaceLockDTO getNamespaceLock(String appId, String env, String clusterName, String namespaceName) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/lock", escapePath(env), escapePath(appId),
      escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenNamespaceLockDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Get namespace lock for appId: %s, cluster: %s, namespace: %s in env: %s failed", appId, clusterName,
            namespaceName, env), ex);
  }
}
 
Example 3
Source File: NamespaceOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public List<OpenNamespaceDTO> getNamespaces(String appId, String env, String clusterName) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces", escapePath(env), escapePath(appId),
      escapePath(clusterName));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OPEN_NAMESPACE_DTO_LIST_TYPE);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Get namespaces for appId: %s, cluster: %s in env: %s failed", appId, clusterName, env), ex);
  }
}
 
Example 4
Source File: NamespaceOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenNamespaceDTO getNamespace(String appId, String env, String clusterName, String namespaceName) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s", escapePath(env), escapePath(appId),
      escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenNamespaceDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Get namespace for appId: %s, cluster: %s, namespace: %s in env: %s failed", appId, clusterName,
            namespaceName, env), ex);
  }
}
 
Example 5
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public void removeItem(String appId, String env, String clusterName, String namespaceName, String key, String operator) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(key, "Item key");
  checkNotEmpty(operator, "Operator");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s?operator=%s",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key),
      escapeParam(operator));

  try (CloseableHttpResponse ignored = delete(path)) {
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Remove item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId,
            clusterName, namespaceName, env), ex);
  }

}
 
Example 6
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public void updateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(itemDTO.getKey(), "Item key");
  checkNotEmpty(itemDTO.getDataChangeLastModifiedBy(), "Item modified by");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName),
      escapePath(itemDTO.getKey()));

  try (CloseableHttpResponse ignored = put(path, itemDTO)) {
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Update item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", itemDTO.getKey(),
            appId, clusterName, namespaceName, env), ex);
  }
}
 
Example 7
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenItemDTO createItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(itemDTO.getKey(), "Item key");
  checkNotEmpty(itemDTO.getDataChangeCreatedBy(), "Item created by");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = post(path, itemDTO)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Create item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", itemDTO.getKey(),
            appId, clusterName, namespaceName, env), ex);
  }
}
 
Example 8
Source File: ReleaseOpenApiService.java    From apollo with Apache License 2.0 6 votes vote down vote up
public OpenReleaseDTO publishNamespace(String appId, String env, String clusterName, String namespaceName,
    NamespaceReleaseDTO releaseDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(releaseDTO.getReleaseTitle(), "Release title");
  checkNotEmpty(releaseDTO.getReleasedBy(), "Released by");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/releases",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName));

  try (CloseableHttpResponse response = post(path, releaseDTO)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenReleaseDTO.class);
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("Release namespace: %s for appId: %s, cluster: %s in env: %s failed", namespaceName, appId,
            clusterName, env), ex);
  }
}
 
Example 9
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 5 votes vote down vote up
public void createOrUpdateItem(String appId, String env, String clusterName, String namespaceName, OpenItemDTO itemDTO) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(itemDTO.getKey(), "Item key");
  checkNotEmpty(itemDTO.getDataChangeCreatedBy(), "Item created by");

  if (Strings.isNullOrEmpty(itemDTO.getDataChangeLastModifiedBy())) {
    itemDTO.setDataChangeLastModifiedBy(itemDTO.getDataChangeCreatedBy());
  }

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s?createIfNotExists=true",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName),
      escapePath(itemDTO.getKey()));

  try (CloseableHttpResponse ignored = put(path, itemDTO)) {
  } catch (Throwable ex) {
    throw new RuntimeException(String
        .format("CreateOrUpdate item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", itemDTO.getKey(),
            appId, clusterName, namespaceName, env), ex);
  }
}
 
Example 10
Source File: ItemOpenApiService.java    From apollo with Apache License 2.0 5 votes vote down vote up
public OpenItemDTO getItem(String appId, String env, String clusterName, String namespaceName, String key) {
  if (Strings.isNullOrEmpty(clusterName)) {
    clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
  if (Strings.isNullOrEmpty(namespaceName)) {
    namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  }

  checkNotEmpty(appId, "App id");
  checkNotEmpty(env, "Env");
  checkNotEmpty(key, "Item key");

  String path = String.format("envs/%s/apps/%s/clusters/%s/namespaces/%s/items/%s",
      escapePath(env), escapePath(appId), escapePath(clusterName), escapePath(namespaceName), escapePath(key));

  try (CloseableHttpResponse response = get(path)) {
    return gson.fromJson(EntityUtils.toString(response.getEntity()), OpenItemDTO.class);
  } catch (Throwable ex) {
    // return null if item doesn't exist
    if (ex instanceof ApolloOpenApiException && ((ApolloOpenApiException)ex).getStatus() == 404) {
      return null;
    }
    throw new RuntimeException(String
        .format("Get item: %s for appId: %s, cluster: %s, namespace: %s in env: %s failed", key, appId, clusterName,
            namespaceName, env), ex);
  }
}
 
Example 11
Source File: WatchKeysUtilTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  watchKeysUtil = new WatchKeysUtil(appNamespaceService);

  someAppId = "someId";
  someCluster = "someCluster";
  someNamespace = "someName";
  anotherNamespace = "anotherName";
  somePublicNamespace = "somePublicName";
  defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  someDC = "someDC";
  somePublicAppId = "somePublicId";

  when(someAppNamespace.getName()).thenReturn(someNamespace);
  when(anotherAppNamespace.getName()).thenReturn(anotherNamespace);
  when(appNamespaceService.findByAppIdAndNamespaces(someAppId, Sets.newHashSet(someNamespace)))
      .thenReturn(Lists.newArrayList(someAppNamespace));
  when(appNamespaceService
      .findByAppIdAndNamespaces(someAppId, Sets.newHashSet(someNamespace, anotherNamespace)))
      .thenReturn(Lists.newArrayList(someAppNamespace, anotherAppNamespace));
  when(appNamespaceService
      .findByAppIdAndNamespaces(someAppId,
          Sets.newHashSet(someNamespace, anotherNamespace, somePublicNamespace)))
      .thenReturn(Lists.newArrayList(someAppNamespace, anotherAppNamespace));

  when(somePublicAppNamespace.getAppId()).thenReturn(somePublicAppId);
  when(somePublicAppNamespace.getName()).thenReturn(somePublicNamespace);
  when(appNamespaceService.findPublicNamespacesByNames(Sets.newHashSet(somePublicNamespace)))
      .thenReturn(Lists.newArrayList(somePublicAppNamespace));
  when(appNamespaceService.findPublicNamespacesByNames(Sets.newHashSet(someNamespace, somePublicNamespace)))
      .thenReturn(Lists.newArrayList(somePublicAppNamespace));
}
 
Example 12
Source File: ConfigUtil.java    From apollo with Apache License 2.0 5 votes vote down vote up
private void initCluster() {
  //Load data center from system property
  cluster = System.getProperty(ConfigConsts.APOLLO_CLUSTER_KEY);

  //Use data center as cluster
  if (Strings.isNullOrEmpty(cluster)) {
    cluster = getDataCenter();
  }

  //Use default cluster
  if (Strings.isNullOrEmpty(cluster)) {
    cluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  }
}
 
Example 13
Source File: ConfigServiceTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Test
public void testCompareTargetNamespaceHasNoItems() {
  ItemDTO sourceItem1 = new ItemDTO("a", "b", "comment", 1);
  List<ItemDTO> sourceItems = Arrays.asList(sourceItem1);

  String appId = "6666", env = "LOCAL", clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT,
      namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  List<NamespaceIdentifier>
      namespaceIdentifiers =
      generateNamespaceIdentifier(appId, env, clusterName, namespaceName);
  NamespaceDTO namespaceDTO = generateNamespaceDTO(appId, clusterName, namespaceName);

  when(namespaceAPI.loadNamespace(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(namespaceDTO);
  when(itemAPI.findItems(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(null);

  UserInfo userInfo = new UserInfo();
  userInfo.setUserId("test");
  when(userInfoHolder.getUser()).thenReturn(userInfo);

  List<ItemDiffs> itemDiffses = configService.compare(namespaceIdentifiers, sourceItems);

  assertEquals(1, itemDiffses.size());
  ItemDiffs itemDiffs = itemDiffses.get(0);
  ItemChangeSets changeSets = itemDiffs.getDiffs();
  assertEquals(0, changeSets.getUpdateItems().size());
  assertEquals(0, changeSets.getDeleteItems().size());

  List<ItemDTO> createItems = changeSets.getCreateItems();
  ItemDTO createItem = createItems.get(0);
  assertEquals(1, createItem.getLineNum());
  assertEquals("a", createItem.getKey());
  assertEquals("b", createItem.getValue());
  assertEquals("comment", createItem.getComment());
}
 
Example 14
Source File: ConfigControllerIntegrationTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ReflectionTestUtils.invokeMethod(appNamespaceServiceWithCache, "reset");

  someAppId = "someAppId";
  someCluster = "someCluster";
  someNamespace = "someNamespace";
  somePublicAppId = "somePublicAppId";
  somePublicNamespace = "somePublicNamespace";
  someDC = "someDC";
  someDefaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  someClientIp = "1.1.1.1";
  executorService = Executors.newSingleThreadExecutor();
}
 
Example 15
Source File: NotificationControllerIntegrationTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ReflectionTestUtils.invokeMethod(releaseMessageServiceWithCache, "reset");
  ReflectionTestUtils.invokeMethod(appNamespaceServiceWithCache, "reset");
  someAppId = "someAppId";
  someCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespace = "somePublicNamespace";
  executorService = Executors.newSingleThreadExecutor();
}
 
Example 16
Source File: NotificationControllerV2IntegrationTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ReflectionTestUtils.invokeMethod(releaseMessageServiceWithCache, "reset");
  someAppId = "someAppId";
  someCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespace = "somePublicNamespace";
  executorService = Executors.newSingleThreadExecutor();
  typeReference = new ParameterizedTypeReference<List<ApolloConfigNotification>>() {
  };
}
 
Example 17
Source File: ConfigFileControllerIntegrationTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  ReflectionTestUtils.invokeMethod(appNamespaceServiceWithCache, "reset");
  someDefaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  someAppId = "someAppId";
  somePublicAppId = "somePublicAppId";
  someCluster = "someCluster";
  someNamespace = "someNamespace";
  somePublicNamespace = "somePublicNamespace";
  someDC = "someDC";
  grayClientIp = "1.1.1.1";
  nonGrayClientIp = "2.2.2.2";
  executorService = Executors.newSingleThreadExecutor();
}
 
Example 18
Source File: NotificationControllerV2Test.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  gson = new Gson();
  controller = new NotificationControllerV2(
      watchKeysUtil, releaseMessageService, entityManagerUtil, namespaceUtil, gson, bizConfig
  );

  when(bizConfig.releaseMessageNotificationBatch()).thenReturn(100);
  when(bizConfig.releaseMessageNotificationBatchIntervalInMilli()).thenReturn(5);

  someAppId = "someAppId";
  someCluster = "someCluster";
  defaultCluster = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespace = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespace = "somePublicNamespace";
  someDataCenter = "someDC";
  someNotificationId = 1;
  someClientIp = "someClientIp";

  when(namespaceUtil.filterNamespaceName(defaultNamespace)).thenReturn(defaultNamespace);
  when(namespaceUtil.filterNamespaceName(somePublicNamespace)).thenReturn(somePublicNamespace);
  when(namespaceUtil.normalizeNamespace(someAppId, defaultNamespace)).thenReturn(defaultNamespace);
  when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespace)).thenReturn(somePublicNamespace);

  deferredResults =
      (Multimap<String, DeferredResultWrapper>) ReflectionTestUtils.getField(controller, "deferredResults");
}
 
Example 19
Source File: ConfigControllerTest.java    From apollo with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  configController = spy(new ConfigController(
      configService, appNamespaceService, namespaceUtil, instanceConfigAuditUtil, gson
  ));

  someAppId = "1";
  someClusterName = "someClusterName";
  defaultClusterName = ConfigConsts.CLUSTER_NAME_DEFAULT;
  defaultNamespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  somePublicNamespaceName = "somePublicNamespace";
  someDataCenter = "someDC";
  someClientIp = "someClientIp";
  String someValidConfiguration = "{\"apollo.bar\": \"foo\"}";
  String somePublicConfiguration = "{\"apollo.public.bar\": \"foo\"}";

  when(someRelease.getAppId()).thenReturn(someAppId);
  when(someRelease.getClusterName()).thenReturn(someClusterName);
  when(someRelease.getConfigurations()).thenReturn(someValidConfiguration);
  when(somePublicRelease.getConfigurations()).thenReturn(somePublicConfiguration);
  when(namespaceUtil.filterNamespaceName(defaultNamespaceName)).thenReturn(defaultNamespaceName);
  when(namespaceUtil.filterNamespaceName(somePublicNamespaceName)).thenReturn(somePublicNamespaceName);
  when(namespaceUtil.normalizeNamespace(someAppId, defaultNamespaceName)).thenReturn(defaultNamespaceName);
  when(namespaceUtil.normalizeNamespace(someAppId, somePublicNamespaceName)).thenReturn(somePublicNamespaceName);

  someMessagesAsString = "someValidJson";
  when(configController.transformMessages(someMessagesAsString)).thenReturn(someNotificationMessages);
}
 
Example 20
Source File: ConfigServiceTest.java    From apollo with Apache License 2.0 4 votes vote down vote up
@Test
public void testCompare() {
  ItemDTO sourceItem1 = new ItemDTO("a", "b", "comment", 1);//not modified
  ItemDTO sourceItem2 = new ItemDTO("newKey", "c", "comment", 2);//new item
  ItemDTO sourceItem3 = new ItemDTO("c", "newValue", "comment", 3);// update value
  ItemDTO sourceItem4 = new ItemDTO("d", "b", "newComment", 4);// update comment
  List<ItemDTO> sourceItems = Arrays.asList(sourceItem1, sourceItem2, sourceItem3, sourceItem4);

  ItemDTO targetItem1 = new ItemDTO("a", "b", "comment", 1);
  ItemDTO targetItem2 = new ItemDTO("c", "oldValue", "comment", 2);
  ItemDTO targetItem3 = new ItemDTO("d", "b", "oldComment", 3);
  List<ItemDTO> targetItems = Arrays.asList(targetItem1, targetItem2, targetItem3);

  String appId = "6666", env = "LOCAL", clusterName = ConfigConsts.CLUSTER_NAME_DEFAULT,
      namespaceName = ConfigConsts.NAMESPACE_APPLICATION;
  List<NamespaceIdentifier>
      namespaceIdentifiers =
      generateNamespaceIdentifier(appId, env, clusterName, namespaceName);
  NamespaceDTO namespaceDTO = generateNamespaceDTO(appId, clusterName, namespaceName);

  when(namespaceAPI.loadNamespace(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(namespaceDTO);
  when(itemAPI.findItems(appId, Env.valueOf(env), clusterName, namespaceName)).thenReturn(targetItems);

  UserInfo userInfo = new UserInfo();
  userInfo.setUserId("test");
  when(userInfoHolder.getUser()).thenReturn(userInfo);

  List<ItemDiffs> itemDiffses = configService.compare(namespaceIdentifiers, sourceItems);
  assertEquals(1, itemDiffses.size());

  ItemDiffs itemDiffs = itemDiffses.get(0);

  ItemChangeSets changeSets = itemDiffs.getDiffs();
  assertEquals(0, changeSets.getDeleteItems().size());
  assertEquals(2, changeSets.getUpdateItems().size());
  assertEquals(1, changeSets.getCreateItems().size());

  NamespaceIdentifier namespaceIdentifier = itemDiffs.getNamespace();
  assertEquals(appId, namespaceIdentifier.getAppId());
  assertEquals(Env.valueOf("LOCAL"), namespaceIdentifier.getEnv());
  assertEquals(clusterName, namespaceIdentifier.getClusterName());
  assertEquals(namespaceName, namespaceIdentifier.getNamespaceName());

  ItemDTO createdItem = changeSets.getCreateItems().get(0);
  assertEquals("newKey", createdItem.getKey());
  assertEquals("c", createdItem.getValue());
  assertEquals("comment", createdItem.getComment());
  assertEquals(4, createdItem.getLineNum());

  List<ItemDTO> updateItems = changeSets.getUpdateItems();
  ItemDTO updateItem1 = updateItems.get(0);
  ItemDTO updateItem2 = updateItems.get(1);
  assertEquals("c", updateItem1.getKey());
  assertEquals("newValue", updateItem1.getValue());
  assertEquals("comment", updateItem1.getComment());
  assertEquals(2, updateItem1.getLineNum());

  assertEquals("d", updateItem2.getKey());
  assertEquals("b", updateItem2.getValue());
  assertEquals("newComment", updateItem2.getComment());
  assertEquals(3, updateItem2.getLineNum());


}