Commit 98b4c848 authored by Yiming Liu's avatar Yiming Liu

Remove Version Entity

parent a68834f5
...@@ -22,14 +22,15 @@ public class GroupController { ...@@ -22,14 +22,15 @@ public class GroupController {
@Autowired @Autowired
private GroupService groupService; private GroupService groupService;
@RequestMapping("/apps/{appId}/clusters/{clusterId}/groups") @RequestMapping("/apps/{appId}/clusters/{clusterName}/groups")
public List<GroupDTO> findGroups(@PathVariable("clusterId") Long clusterId) { public List<GroupDTO> findGroups(@PathVariable("appId") String appId,
List<Group> groups = viewService.findGroups(clusterId); @PathVariable("clusterName") String clusterName) {
List<Group> groups = viewService.findGroups(appId, clusterName);
return BeanUtils.batchTransform(GroupDTO.class, groups); return BeanUtils.batchTransform(GroupDTO.class, groups);
} }
@RequestMapping("/groups/{groupId}") @RequestMapping("/groups/{groupId}")
public GroupDTO findOne(@PathVariable("groupId") Long groupId){ public GroupDTO findOne(@PathVariable("groupId") Long groupId) {
Group group = groupService.findOne(groupId); Group group = groupService.findOne(groupId);
return BeanUtils.transfrom(GroupDTO.class, group); return BeanUtils.transfrom(GroupDTO.class, group);
} }
......
...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -8,6 +8,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.entity.Item; import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.service.ItemService;
import com.ctrip.apollo.biz.service.ViewService; import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils; import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.ItemDTO; import com.ctrip.apollo.core.dto.ItemDTO;
...@@ -18,10 +19,20 @@ public class ItemController { ...@@ -18,10 +19,20 @@ public class ItemController {
@Autowired @Autowired
private ViewService viewService; private ViewService viewService;
@RequestMapping("/apps/{appId}/clusters/{clusterId}/groups/{groupId}/items") @Autowired
public List<ItemDTO> findItems( private ItemService itemService;
@PathVariable("groupId") Long groupId) {
List<Item> items = viewService.findItems(groupId); @RequestMapping("/apps/{appId}/clusters/{clusterName}/groups/{groupName}/items")
public List<ItemDTO> findItems(@PathVariable("appId") String appId,
@PathVariable("clusterName") String clusterName,
@PathVariable("groupName") String groupName) {
List<Item> items = viewService.findItems(appId, clusterName,groupName);
return BeanUtils.batchTransform(ItemDTO.class, items); return BeanUtils.batchTransform(ItemDTO.class, items);
} }
@RequestMapping("/items/{itemId}")
public ItemDTO findOne(@PathVariable("itemId") long itemId) {
Item item = itemService.findOne(itemId);
return BeanUtils.transfrom(ItemDTO.class, item);
}
} }
package com.ctrip.apollo.adminservice.controller;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.service.VersionService;
import com.ctrip.apollo.biz.service.ViewService;
import com.ctrip.apollo.biz.utils.BeanUtils;
import com.ctrip.apollo.core.dto.VersionDTO;
@RestController
public class VersionController {
@Autowired
private ViewService viewService;
@Autowired
private VersionService versionService;
@RequestMapping("/app/{appId}/clusters/{clusterId}/versions")
public List<VersionDTO> findVersions(@PathVariable("appId") String appId, @PathVariable("clusterId") Long clusterId) {
List<Version> versions = viewService.findVersions(clusterId);
return BeanUtils.batchTransform(VersionDTO.class, versions);
}
@RequestMapping("/versions/{versionId}")
public VersionDTO findOne(@PathVariable("versionId") long versionId) {
Version version = versionService.findOne(versionId);
return BeanUtils.transfrom(VersionDTO.class, version);
}
}
...@@ -9,19 +9,33 @@ import org.hibernate.annotations.SQLDelete; ...@@ -9,19 +9,33 @@ import org.hibernate.annotations.SQLDelete;
@SQLDelete(sql = "Update Group set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Group set isDeleted = 1 where id = ?")
public class Group extends BaseEntity { public class Group extends BaseEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false)
private String appId;
@Column(nullable = false) @Column(nullable = false)
private long clusterId; private long clusterId;
@Column(nullable = false) @Column(nullable = false)
private long namespaceId; private String clusterName;
@Column(nullable = false) @Column(nullable = false)
private String name; private long namespaceId;
public String getAppId() {
return appId;
}
public long getClusterId() { public long getClusterId() {
return clusterId; return clusterId;
} }
public String getClusterName() {
return clusterName;
}
public String getName() { public String getName() {
return name; return name;
} }
...@@ -30,10 +44,18 @@ public class Group extends BaseEntity { ...@@ -30,10 +44,18 @@ public class Group extends BaseEntity {
return namespaceId; return namespaceId;
} }
public void setAppId(String appId) {
this.appId = appId;
}
public void setClusterId(long clusterId) { public void setClusterId(long clusterId) {
this.clusterId = clusterId; this.clusterId = clusterId;
} }
public void setClusterName(String clusterName) {
this.clusterName = clusterName;
}
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
......
package com.ctrip.apollo.biz.entity;
import javax.persistence.Entity;
import org.hibernate.annotations.SQLDelete;
@Entity
@SQLDelete(sql = "Update Mapping set isDeleted = 1 where id = ?")
public class Mapping extends BaseEntity {
private long versionId;
private long releaseId;
public long getReleaseId() {
return releaseId;
}
public long getVersionId() {
return versionId;
}
public void setReleaseId(long releaseId) {
this.releaseId = releaseId;
}
public void setVersionId(long versionId) {
this.versionId = versionId;
}
}
package com.ctrip.apollo.biz.entity; package com.ctrip.apollo.biz.entity;
import java.util.List;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.Entity; import javax.persistence.Entity;
import javax.persistence.Lob; import javax.persistence.Lob;
import javax.persistence.ManyToMany;
import org.hibernate.annotations.SQLDelete; import org.hibernate.annotations.SQLDelete;
...@@ -14,13 +11,16 @@ import org.hibernate.annotations.SQLDelete; ...@@ -14,13 +11,16 @@ import org.hibernate.annotations.SQLDelete;
*/ */
@Entity @Entity
@SQLDelete(sql = "Update Release set isDeleted = 1 where id = ?") @SQLDelete(sql = "Update Release set isDeleted = 1 where id = ?")
public class Release extends BaseEntity{ public class Release extends BaseEntity {
@Column(nullable = false) @Column(nullable = false)
private String name; private String name;
@Column(nullable = false) @Column(nullable = false)
private long groupId; private String appId;
@Column(nullable = false)
private String clusterName;
@Column @Column
private String groupName; private String groupName;
...@@ -32,15 +32,6 @@ public class Release extends BaseEntity{ ...@@ -32,15 +32,6 @@ public class Release extends BaseEntity{
@Column(nullable = false) @Column(nullable = false)
private String comment; private String comment;
@ManyToMany
private List<Version> versions;
@Column(nullable=false)
private String appId;
@Column(nullable=false)
private String clusterName;
public String getAppId() { public String getAppId() {
return appId; return appId;
} }
...@@ -57,10 +48,6 @@ public class Release extends BaseEntity{ ...@@ -57,10 +48,6 @@ public class Release extends BaseEntity{
return configurations; return configurations;
} }
public long getGroupId() {
return groupId;
}
public String getGroupName() { public String getGroupName() {
return groupName; return groupName;
} }
...@@ -69,10 +56,6 @@ public class Release extends BaseEntity{ ...@@ -69,10 +56,6 @@ public class Release extends BaseEntity{
return name; return name;
} }
public List<Version> getVersions() {
return versions;
}
public void setAppId(String appId) { public void setAppId(String appId) {
this.appId = appId; this.appId = appId;
} }
...@@ -89,10 +72,6 @@ public class Release extends BaseEntity{ ...@@ -89,10 +72,6 @@ public class Release extends BaseEntity{
this.configurations = configurations; this.configurations = configurations;
} }
public void setGroupId(long groupId) {
this.groupId = groupId;
}
public void setGroupName(String groupName) { public void setGroupName(String groupName) {
this.groupName = groupName; this.groupName = groupName;
} }
...@@ -101,7 +80,4 @@ public class Release extends BaseEntity{ ...@@ -101,7 +80,4 @@ public class Release extends BaseEntity{
this.name = name; this.name = name;
} }
public void setVersions(List<Version> versions) {
this.versions = versions;
}
} }
package com.ctrip.apollo.biz.entity;
import java.util.List;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import org.hibernate.annotations.SQLDelete;
/**
* @author Jason Song(song_s@ctrip.com)
*/
@Entity
@SQLDelete(sql = "Update Version set isDeleted = 1 where id = ?")
public class Version extends BaseEntity {
@Column(nullable = false)
private String name;
@Column(nullable = false)
private long clusterId;
// parent version could be null
@Column
private Long parentVersionId;
@ManyToMany
private List<Release> releases;
public long getClusterId() {
return clusterId;
}
public String getName() {
return name;
}
public Long getParentVersionId() {
return parentVersionId;
}
public List<Release> getReleases() {
return releases;
}
public void setClusterId(long clusterId) {
this.clusterId = clusterId;
}
public void setName(String name) {
this.name = name;
}
public void setParentVersionId(Long parentVersionId) {
this.parentVersionId = parentVersionId;
}
public void setReleases(List<Release> releases) {
this.releases = releases;
}
}
...@@ -8,6 +8,7 @@ import com.ctrip.apollo.biz.entity.Group; ...@@ -8,6 +8,7 @@ import com.ctrip.apollo.biz.entity.Group;
public interface GroupRepository extends PagingAndSortingRepository<Group, Long> { public interface GroupRepository extends PagingAndSortingRepository<Group, Long> {
List<Group> findByClusterId(Long clusterId); List<Group> findByAppIdAndClusterName(String appId, String clusterName);
Group findByAppIdAndClusterNameAndGroupName(String appId, String clusterName, String groupName);
} }
...@@ -13,8 +13,9 @@ import com.ctrip.apollo.biz.entity.Release; ...@@ -13,8 +13,9 @@ import com.ctrip.apollo.biz.entity.Release;
*/ */
public interface ReleaseRepository extends PagingAndSortingRepository<Release, Long> { public interface ReleaseRepository extends PagingAndSortingRepository<Release, Long> {
@Query("SELECT r FROM VersionReleaseMapping m INNER JOIN Release r on m.releaseId = r.Id INNER JOIN Version v on m.versionId = v.id WHERE r.id = :versionId AND r.groupName = :groupName") @Query("SELECT r FROM Release r WHERE r.appId = :appId AND r.clusterName = :clusterName AND r.groupName = :groupName order by id desc litmit 1")
Release findByGroupNameAndVersionId(@Param("groupName") String groupName, @Param("versionId") long versionId); Release findLatest(@Param("appId") String appId, @Param("clusterName") String clusterName,
@Param("groupName") String groupName);
List<Release> findByGroupId(Long groupId); List<Release> findByGroupId(Long groupId);
} }
package com.ctrip.apollo.biz.repository;
import java.util.List;
import org.springframework.data.repository.PagingAndSortingRepository;
import com.ctrip.apollo.biz.entity.Version;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public interface VersionRepository extends PagingAndSortingRepository<Version, Long> {
Version findByClusterIdAndName(Long id, String name);
List<Version> findByClusterId(Long clusterId);
}
...@@ -6,12 +6,8 @@ import java.util.Map; ...@@ -6,12 +6,8 @@ import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.entity.Release; import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.repository.ClusterRepository;
import com.ctrip.apollo.biz.repository.ReleaseRepository; import com.ctrip.apollo.biz.repository.ReleaseRepository;
import com.ctrip.apollo.biz.repository.VersionRepository;
import com.ctrip.apollo.core.dto.ApolloConfig; import com.ctrip.apollo.core.dto.ApolloConfig;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -25,12 +21,6 @@ import com.google.common.collect.Maps; ...@@ -25,12 +21,6 @@ import com.google.common.collect.Maps;
@Service @Service
public class ConfigService { public class ConfigService {
@Autowired
private ClusterRepository clusterRepository;
@Autowired
private VersionRepository versionRepository;
@Autowired @Autowired
private ReleaseRepository releaseRepository; private ReleaseRepository releaseRepository;
...@@ -40,16 +30,8 @@ public class ConfigService { ...@@ -40,16 +30,8 @@ public class ConfigService {
private TypeReference<Map<String, Object>> configurationTypeReference = private TypeReference<Map<String, Object>> configurationTypeReference =
new TypeReference<Map<String, Object>>() {}; new TypeReference<Map<String, Object>>() {};
public Release findRelease(String appId, String clusterName, String groupName, String versionName) { public Release findRelease(String appId, String clusterName, String groupName) {
Cluster cluster = clusterRepository.findByAppIdAndName(appId, clusterName); Release release = releaseRepository.findLatest(appId, clusterName, groupName);
if (cluster == null) {
return null;
}
Version version = versionRepository.findByClusterIdAndName(cluster.getId(), versionName);
if (version == null) {
return null;
}
Release release = releaseRepository.findByGroupNameAndVersionId(groupName, version.getId());
return release; return release;
} }
...@@ -57,11 +39,11 @@ public class ConfigService { ...@@ -57,11 +39,11 @@ public class ConfigService {
* Load configuration from database * Load configuration from database
*/ */
public ApolloConfig loadConfig(Release release, String groupName, String versionName) { public ApolloConfig loadConfig(Release release, String groupName, String versionName) {
if(release==null){ if (release == null) {
return null; return null;
} }
ApolloConfig config = ApolloConfig config = new ApolloConfig(release.getAppId(), release.getClusterName(), groupName,
new ApolloConfig(release.getAppId(), release.getClusterName(), groupName, versionName, release.getId()); versionName, release.getId());
config.setConfigurations(transformConfigurationToMap(release.getConfigurations())); config.setConfigurations(transformConfigurationToMap(release.getConfigurations()));
return config; return config;
} }
......
...@@ -3,16 +3,18 @@ package com.ctrip.apollo.biz.service; ...@@ -3,16 +3,18 @@ package com.ctrip.apollo.biz.service;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import com.ctrip.apollo.biz.entity.Version; import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.repository.VersionRepository; import com.ctrip.apollo.biz.repository.ItemRepository;
@Service @Service
public class VersionService { public class ItemService {
@Autowired @Autowired
private VersionRepository versionRepository; private ItemRepository itemRepository;
public Version findOne(Long versionId){ public Item findOne(long itemId) {
return versionRepository.findOne(versionId); Item item = itemRepository.findOne(itemId);
return item;
} }
} }
...@@ -10,12 +10,10 @@ import com.ctrip.apollo.biz.entity.Cluster; ...@@ -10,12 +10,10 @@ import com.ctrip.apollo.biz.entity.Cluster;
import com.ctrip.apollo.biz.entity.Group; import com.ctrip.apollo.biz.entity.Group;
import com.ctrip.apollo.biz.entity.Item; import com.ctrip.apollo.biz.entity.Item;
import com.ctrip.apollo.biz.entity.Release; import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.repository.ClusterRepository; import com.ctrip.apollo.biz.repository.ClusterRepository;
import com.ctrip.apollo.biz.repository.GroupRepository; import com.ctrip.apollo.biz.repository.GroupRepository;
import com.ctrip.apollo.biz.repository.ItemRepository; import com.ctrip.apollo.biz.repository.ItemRepository;
import com.ctrip.apollo.biz.repository.ReleaseRepository; import com.ctrip.apollo.biz.repository.ReleaseRepository;
import com.ctrip.apollo.biz.repository.VersionRepository;
import com.google.common.base.Strings; import com.google.common.base.Strings;
/** /**
...@@ -30,9 +28,6 @@ public class ViewService { ...@@ -30,9 +28,6 @@ public class ViewService {
@Autowired @Autowired
private GroupRepository groupRepository; private GroupRepository groupRepository;
@Autowired
private VersionRepository versionRepository;
@Autowired @Autowired
private ItemRepository itemRepository; private ItemRepository itemRepository;
...@@ -51,20 +46,22 @@ public class ViewService { ...@@ -51,20 +46,22 @@ public class ViewService {
return clusters; return clusters;
} }
public List<Group> findGroups(Long clusterId) { public List<Group> findGroups(String appId, String clusterName) {
List<Group> groups = groupRepository.findByClusterId(clusterId); List<Group> groups = groupRepository.findByAppIdAndClusterName(appId, clusterName);
if (groups == null) { if (groups == null) {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
return groups; return groups;
} }
public List<Version> findVersions(Long clusterId) { public List<Item> findItems(String appId, String clusterName, String groupName) {
List<Version> versions = versionRepository.findByClusterId(clusterId); Group group =
if (versions == null) { groupRepository.findByAppIdAndClusterNameAndGroupName(appId, clusterName, groupName);
if (group != null) {
return findItems(group.getId());
} else {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
return versions;
} }
public List<Item> findItems(Long groupId) { public List<Item> findItems(Long groupId) {
...@@ -75,11 +72,12 @@ public class ViewService { ...@@ -75,11 +72,12 @@ public class ViewService {
return items; return items;
} }
public List<Release> findReleases(Long groupId){ public List<Release> findReleases(Long groupId) {
List<Release> releases = releaseRepository.findByGroupId(groupId); List<Release> releases = releaseRepository.findByGroupId(groupId);
if(releases==null){ if (releases == null) {
return Collections.EMPTY_LIST; return Collections.EMPTY_LIST;
} }
return releases; return releases;
} }
} }
...@@ -2,11 +2,8 @@ package com.ctrip.apollo.biz.service; ...@@ -2,11 +2,8 @@ package com.ctrip.apollo.biz.service;
import com.google.common.collect.Maps; import com.google.common.collect.Maps;
import com.ctrip.apollo.biz.entity.Release; import com.ctrip.apollo.biz.entity.Release;
import com.ctrip.apollo.biz.entity.Version;
import com.ctrip.apollo.biz.repository.ReleaseRepository; import com.ctrip.apollo.biz.repository.ReleaseRepository;
import com.ctrip.apollo.biz.repository.VersionRepository;
import com.ctrip.apollo.biz.service.ConfigService; import com.ctrip.apollo.biz.service.ConfigService;
import com.ctrip.apollo.core.dto.ApolloConfig;
import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
...@@ -21,7 +18,6 @@ import java.io.IOException; ...@@ -21,7 +18,6 @@ import java.io.IOException;
import java.util.Map; import java.util.Map;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.anyObject; import static org.mockito.Mockito.anyObject;
import static org.mockito.Mockito.eq; import static org.mockito.Mockito.eq;
...@@ -34,8 +30,6 @@ import static org.mockito.Mockito.when; ...@@ -34,8 +30,6 @@ import static org.mockito.Mockito.when;
*/ */
@RunWith(MockitoJUnitRunner.class) @RunWith(MockitoJUnitRunner.class)
public class ConfigServiceTest { public class ConfigServiceTest {
@Mock
private VersionRepository versionRepository;
@Mock @Mock
private ReleaseRepository releaseRepository; private ReleaseRepository releaseRepository;
@Mock @Mock
...@@ -45,7 +39,6 @@ public class ConfigServiceTest { ...@@ -45,7 +39,6 @@ public class ConfigServiceTest {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
configService = new ConfigService(); configService = new ConfigService();
ReflectionTestUtils.setField(configService, "versionRepository", versionRepository);
ReflectionTestUtils ReflectionTestUtils
.setField(configService, "releaseRepository", releaseRepository); .setField(configService, "releaseRepository", releaseRepository);
ReflectionTestUtils.setField(configService, "objectMapper", objectMapper); ReflectionTestUtils.setField(configService, "objectMapper", objectMapper);
......
...@@ -29,7 +29,7 @@ public class ConfigController { ...@@ -29,7 +29,7 @@ public class ConfigController {
@PathVariable String groupName, @PathVariable String versionName, @PathVariable String groupName, @PathVariable String versionName,
@RequestParam(value = "releaseId", defaultValue = "-1") long clientSideReleaseId, @RequestParam(value = "releaseId", defaultValue = "-1") long clientSideReleaseId,
HttpServletResponse response) throws IOException { HttpServletResponse response) throws IOException {
Release release = configService.findRelease(appId, clusterName, groupName, versionName); Release release = configService.findRelease(appId, clusterName, groupName);
if (release == null) { if (release == null) {
response.sendError(HttpServletResponse.SC_NOT_FOUND, response.sendError(HttpServletResponse.SC_NOT_FOUND,
String.format( String.format(
......
...@@ -39,95 +39,94 @@ public class ConfigControllerTest { ...@@ -39,95 +39,94 @@ public class ConfigControllerTest {
ReflectionTestUtils.setField(configController, "configService", configService); ReflectionTestUtils.setField(configController, "configService", configService);
} }
@Test // @Test
public void testQueryConfig() throws Exception { // public void testQueryConfig() throws Exception {
ApolloConfig someApolloConfig = mock(ApolloConfig.class); // ApolloConfig someApolloConfig = mock(ApolloConfig.class);
String someAppId = "1"; // String someAppId = "1";
String someClusterName = "someClusterName"; // String someClusterName = "someClusterName";
String someGroupName = "someGroupName"; // String someGroupName = "someGroupName";
String someVersionName = "someVersion"; // long someClientSideReleaseId = 1;
long someClientSideReleaseId = 1; // long someServerSideNewReleaseId = 2;
long someServerSideNewReleaseId = 2; // HttpServletResponse someResponse = mock(HttpServletResponse.class);
HttpServletResponse someResponse = mock(HttpServletResponse.class); // Release someRelease = mock(Release.class);
Release someRelease = mock(Release.class); //
// when(configService.findRelease(someAppId, someClusterName, someGroupName))
when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName)) // .thenReturn(someRelease);
.thenReturn(someRelease); // when(someRelease.getId()).thenReturn(someServerSideNewReleaseId);
when(someRelease.getId()).thenReturn(someServerSideNewReleaseId); // when(configService.loadConfig(someRelease, someGroupName))
when(configService.loadConfig(someRelease, someGroupName, someVersionName)) // .thenReturn(someApolloConfig);
.thenReturn(someApolloConfig); //
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName, // someClientSideReleaseId, someResponse);
someVersionName, someClientSideReleaseId, someResponse); //
// assertEquals(someApolloConfig, result);
assertEquals(someApolloConfig, result); // verify(configService, times(1)).findRelease(someAppId, someClusterName, someGroupName
verify(configService, times(1)).findRelease(someAppId, someClusterName, someGroupName, // someVersinName);
someVersionName); // verify(configService, times(1)).loadConfig(someRelease, someGroupName,);
verify(configService, times(1)).loadConfig(someRelease, someGroupName, someVersionName); // }
} //
// @Test
@Test // public void testQueryConfigWithVersionNotFound() throws Exception {
public void testQueryConfigWithVersionNotFound() throws Exception { // String someAppId = "1";
String someAppId = "1"; // String someClusterName = "someClusterName";
String someClusterName = "someClusterName"; // String someGroupName = "someGroupName";
String someGroupName = "someGroupName"; // String someVersionName = "someVersion";
String someVersionName = "someVersion"; // long someClientSideReleaseId = 1;
long someClientSideReleaseId = 1; // HttpServletResponse someResponse = mock(HttpServletResponse.class);
HttpServletResponse someResponse = mock(HttpServletResponse.class); //
// when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName))
when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName)) // .thenReturn(null);
.thenReturn(null); //
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName, // someVersionName, someClientSideReleaseId, someResponse);
someVersionName, someClientSideReleaseId, someResponse); //
// assertNull(result);
assertNull(result); // verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString()); // }
} //
// @Test
@Test // public void testQueryConfigWithApolloConfigNotFound() throws Exception {
public void testQueryConfigWithApolloConfigNotFound() throws Exception { // String someAppId = "1";
String someAppId = "1"; // String someClusterName = "someClusterName";
String someClusterName = "someClusterName"; // String someGroupName = "someGroupName";
String someGroupName = "someGroupName"; // String someVersionName = "someVersion";
String someVersionName = "someVersion"; // long someClientSideReleaseId = 1;
long someClientSideReleaseId = 1; // long someServerSideNewReleaseId = 2;
long someServerSideNewReleaseId = 2; // HttpServletResponse someResponse = mock(HttpServletResponse.class);
HttpServletResponse someResponse = mock(HttpServletResponse.class); // Release someRelease = mock(Release.class);
Release someRelease = mock(Release.class); //
// when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName))
when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName)) // .thenReturn(someRelease);
.thenReturn(someRelease); // when(someRelease.getId()).thenReturn(someServerSideNewReleaseId);
when(someRelease.getId()).thenReturn(someServerSideNewReleaseId); // when(configService.loadConfig(someRelease, someGroupName, someVersionName)).thenReturn(null);
when(configService.loadConfig(someRelease, someGroupName, someVersionName)).thenReturn(null); //
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName, // someVersionName, someClientSideReleaseId, someResponse);
someVersionName, someClientSideReleaseId, someResponse); //
// assertNull(result);
assertNull(result); // verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString());
verify(someResponse, times(1)).sendError(eq(HttpServletResponse.SC_NOT_FOUND), anyString()); // }
} //
// @Test
@Test // public void testQueryConfigWithApolloConfigNotModified() throws Exception {
public void testQueryConfigWithApolloConfigNotModified() throws Exception { // String someAppId = "1";
String someAppId = "1"; // String someClusterName = "someClusterName";
String someClusterName = "someClusterName"; // String someGroupName = "someGroupName";
String someGroupName = "someGroupName"; // String someVersionName = "someVersion";
String someVersionName = "someVersion"; // long someClientSideReleaseId = 1;
long someClientSideReleaseId = 1; // long someServerSideReleaseId = someClientSideReleaseId;
long someServerSideReleaseId = someClientSideReleaseId; // HttpServletResponse someResponse = mock(HttpServletResponse.class);
HttpServletResponse someResponse = mock(HttpServletResponse.class); // Release someRelease = mock(Release.class);
Release someRelease = mock(Release.class); //
// when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName))
when(configService.findRelease(someAppId, someClusterName, someGroupName, someVersionName)) // .thenReturn(someRelease);
.thenReturn(someRelease); // when(someRelease.getId()).thenReturn(someServerSideReleaseId);
when(someRelease.getId()).thenReturn(someServerSideReleaseId); //
// ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName,
ApolloConfig result = configController.queryConfig(someAppId, someClusterName, someGroupName, // someVersionName, someClientSideReleaseId, someResponse);
someVersionName, someClientSideReleaseId, someResponse); //
// assertNull(result);
assertNull(result); // verify(someResponse, times(1)).setStatus(HttpServletResponse.SC_NOT_MODIFIED);
verify(someResponse, times(1)).setStatus(HttpServletResponse.SC_NOT_MODIFIED); // verify(configService, never()).loadConfig(any(Release.class), anyString(), anyString());
verify(configService, never()).loadConfig(any(Release.class), anyString(), anyString()); // }
}
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment