-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
117 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.datastat.ds.unit; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.MockitoAnnotations; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import com.datastat.config.FoundryConfig; | ||
import com.datastat.config.context.QueryConfContext; | ||
import com.datastat.dao.FoundryDao; | ||
import com.datastat.dao.RedisDao; | ||
import com.datastat.dao.context.QueryDaoContext; | ||
import com.datastat.ds.common.CommonUtil; | ||
import com.datastat.model.dto.RequestParams; | ||
import com.datastat.service.QueryService; | ||
import jakarta.servlet.http.HttpServletRequest; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
public class ServiceUnitTests { | ||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
@Mock | ||
QueryDaoContext queryDaoContext; | ||
|
||
@Mock | ||
QueryConfContext queryConfContext; | ||
|
||
@Mock | ||
private RedisDao redisDao; | ||
|
||
@InjectMocks | ||
private QueryService queryService; | ||
|
||
@Mock | ||
private FoundryConfig queryConfig; | ||
|
||
@Mock | ||
private FoundryDao queryDao; | ||
|
||
@BeforeEach | ||
public void setUp() throws Exception { | ||
MockitoAnnotations.openMocks(this); | ||
} | ||
|
||
@Test() | ||
void testDownloadCountService() throws Exception { | ||
HttpServletRequest request = mock(HttpServletRequest.class); | ||
RequestParams params = new RequestParams(); | ||
params.setRepoType("model"); | ||
|
||
|
||
StringBuilder sb = new StringBuilder("modelfoundrycownload_repo_count_"); | ||
sb.append(params.getPath()) | ||
.append(params.getRepoType()) | ||
.append(params.getRepoId()) | ||
.append(params.getStart()) | ||
.append(params.getEnd()); | ||
String key = sb.toString(); | ||
String result = "{\"code\":200,\"msg\":\"ok\",\"data\":[{\"repo_id\":\"1313\",\"repo\":\"Qwen\",\"download\":30}]}"; | ||
when(redisDao.get(key)).thenReturn(result); | ||
String serviceRes = queryService.queryModelFoundryCountPath(request, params); | ||
CommonUtil.assertOk(serviceRes); | ||
|
||
when(redisDao.get(key)).thenReturn(null); | ||
when(queryDaoContext.getQueryDao("queryDao")).thenReturn(queryDao); | ||
when(queryConfContext.getQueryConfig("foundryConf")).thenReturn(queryConfig); | ||
when(queryDao.queryModelFoundryCountPath(queryConfig, params)).thenReturn(result); | ||
when(redisDao.set(key, result, 1l)).thenReturn(true); | ||
String res = queryService.queryModelFoundryCountPath(request, params); | ||
CommonUtil.assertOk(res); | ||
} | ||
} |