Skip to content

Commit

Permalink
add some test and fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
blackstar-baba committed Nov 24, 2020
1 parent 1b3ed26 commit 811e421
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ public List<AppVersion> getVersionsByAppName(String appName) {
public AppVersion getVersionByNameAndVersion(String appName, String version) {
AppVersion appVersion = this.getOne(new QueryWrapper<AppVersion>().eq(APP_NAME, appName).eq(VERSION, version));
App app = appService.getByName(appName);
if (appVersion == null) {
return null;
}
try {
if (appVersion.getAdditionalInfo() == null) {
appVersion.setAdditionalInfo(app.getAdditionalInfo());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ public ContainerInfo start(ContainerInfo containerInfo) throws PortException {
.withEnv(envs)
// .withHostConfig(hostConfig)
.exec();
System.out.println("kasi");
dockerClient.startContainerCmd(createContainer.getId()).exec();
System.out.println("kasi end");
containerInfo.setId(createContainer.getId());

} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.softwarelab.application.entity.App;
import com.softwarelab.application.service.IAppExtensionService;
import com.softwarelab.application.service.IAppService;
import com.sun.jna.platform.win32.ShellAPI;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -21,14 +22,16 @@ public class AppExtensionServiceTest extends AbstractBaseTest {
@Autowired
private IAppService appService;

private App demoApp;

@Before
public void setUp() throws Exception {
demoApp = getDemoApp();
appService.save(demoApp);
}

@Test
public void addUsedCount() {
App demoApp = getDemoApp();
appService.save(demoApp);
appExtensionService.addUsedCount(demoApp.getName());
assertTrue(appExtensionService.getById(demoApp.getName())!=null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,29 @@ public class AppServiceTest extends AbstractBaseTest {
@Autowired
private IAppService appService;

private App demoApp;

@Before
public void setUp() throws Exception {

demoApp = getDemoApp();
appService.save(demoApp);
}

@Test
public void getNameByType() {
App demoApp = getDemoApp();
appService.save(demoApp);

assertTrue(appService.getNameByType("null").size() == 0);
assertTrue(appService.getNameByType(demoApp.getType()).size() == 1);
}

@Test
public void getByName() {
App demoApp = getDemoApp();
appService.save(demoApp);
assertTrue(appService.getByName("null") == null);
assertTrue(appService.getByName(demoApp.getName()) != null);
}

@Test
public void getTop() {
App demoApp = getDemoApp();
appService.save(demoApp);
assertTrue(appService.getTop(0).size() >= 0);
assertTrue(appService.getTop(1).size() >= 1);
demoApp.setName("demo2");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.softwarelab.application.service;

import com.softwarelab.application.AbstractBaseTest;
import com.softwarelab.application.entity.App;
import com.softwarelab.application.entity.AppVersion;
import org.junit.Before;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

import static org.junit.Assert.*;
import static org.junit.Assert.assertTrue;

@Transactional
public class AppVersionServiceTest extends AbstractBaseTest {


@Autowired
private IAppVersionService appVersionService;

@Autowired
private IAppService appService;

private App demoApp;

private AppVersion demoAppVersion;


@Before
public void setUp() throws Exception {
demoApp = getDemoApp();
appService.save(demoApp);
demoAppVersion = getDemoAppVersion();
appVersionService.save(demoAppVersion);

}

@Test
public void getSimpleByAppName() {
assertTrue(appVersionService.getSimpleByAppName("null").size() == 0);
List<AppVersion> simpleAppVersions = appVersionService.getSimpleByAppName(demoApp.getName());
assertTrue(simpleAppVersions.size() == 1);
AppVersion appVersion = simpleAppVersions.get(0);
assertTrue(appVersion.getVersion() != null);
assertTrue(appVersion.getDownloadStatus() != null);

}

@Test
public void getVersionsByAppName() {
assertTrue(appVersionService.getVersionsByAppName("null").size() == 0);
List<AppVersion> appVersions = appVersionService.getVersionsByAppName(demoApp.getName());
assertTrue(appVersions.size() == 1);
AppVersion appVersion = appVersions.get(0);
assertTrue(appVersion.getAppName() != null);
assertTrue(appVersion.getVersion() != null);
}

@Test
public void getVersionByNameAndVersion() {
assertTrue(appVersionService.getVersionByNameAndVersion("null","null") == null);
AppVersion appVersion = appVersionService.getVersionByNameAndVersion(demoApp.getName(), demoAppVersion.getVersion());
assertTrue(appVersion != null);
assertTrue(appVersion.getAppName() != null);
assertTrue(appVersion.getVersion() != null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ public void testRunCommand() {
containerService.start(containerInfo);
ExecStartResultCallback execStartResultCallback = containerService.runCommand(containerInfo.getId(), command, out);
execStartResultCallback.awaitCompletion();
System.out.println("for what");
assertTrue(new String(out.toByteArray()).startsWith("total"));
} catch (IOException e) {
e.printStackTrace();
Expand All @@ -129,7 +128,6 @@ public void testRunCommand() {
e.printStackTrace();
} finally {
if(containerInfo.getId() != null){
System.out.println("stop");
containerService.stop(containerInfo);
containerService.remove(containerInfo);
}
Expand Down

0 comments on commit 811e421

Please sign in to comment.