Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 9306b26

Browse files
authored
fix: fix Integration tests (#805)
Signed-off-by: Stephane Bouchet <[email protected]>
1 parent ff37076 commit 9306b26

File tree

12 files changed

+1384
-189
lines changed

12 files changed

+1384
-189
lines changed

src/it/java/org/jboss/tools/intellij/openshift/utils/odo/OdoCliComponentTest.java

Lines changed: 98 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -31,115 +31,115 @@
3131

3232
@RunWith(Parameterized.class)
3333
public class OdoCliComponentTest extends OdoCliTest {
34-
private final ComponentFeature feature;
35-
private String project;
36-
private String component;
37-
private String service;
34+
private final ComponentFeature feature;
35+
private String project;
36+
private String component;
37+
private String service;
3838

39-
public OdoCliComponentTest(ComponentFeature feature) {
40-
this.feature = feature;
41-
}
39+
public OdoCliComponentTest(ComponentFeature feature) {
40+
this.feature = feature;
41+
}
4242

43-
@Parameterized.Parameters(name = "feature: {0}")
44-
public static Iterable<?> data() {
45-
return Arrays.asList(null, ComponentFeature.DEV);
46-
}
43+
@Parameterized.Parameters(name = "feature: {0}")
44+
public static Iterable<?> data() {
45+
return Arrays.asList(null, ComponentFeature.DEV);
46+
}
4747

48-
@Before
49-
public void initTestEnv() {
50-
project = PROJECT_PREFIX + random.nextInt();
51-
component = COMPONENT_PREFIX + random.nextInt();
52-
service = SERVICE_PREFIX + random.nextInt();
53-
}
48+
@Before
49+
public void initTestEnv() {
50+
project = PROJECT_PREFIX + random.nextInt();
51+
component = COMPONENT_PREFIX + random.nextInt();
52+
service = SERVICE_PREFIX + random.nextInt();
53+
}
5454

55-
@After
56-
public void cleanUp() throws IOException {
57-
if (odo.isStarted(COMPONENT_PATH, ComponentFeature.DEV)) {
58-
odo.stop(COMPONENT_PATH, component, ComponentFeature.DEV);
59-
}
60-
if (project.equals(odo.getCurrentNamespace())) {
61-
odo.deleteProject(project);
62-
}
55+
@After
56+
public void cleanUp() throws IOException {
57+
if (odo.isStarted(COMPONENT_PATH, ComponentFeature.DEV)) {
58+
odo.stop(COMPONENT_PATH, component, ComponentFeature.DEV);
6359
}
64-
65-
@Test
66-
public void checkCreateComponent() throws IOException, ExecutionException, InterruptedException {
67-
createComponent(project, component, feature);
68-
List<Component> components = odo.getComponents(project);
69-
assertNotNull(components);
70-
assertEquals(feature == ComponentFeature.DEV ? 1 : 0, components.size());
60+
if (project.equals(odo.getCurrentNamespace())) {
61+
odo.deleteProject(project);
7162
}
63+
}
7264

73-
@Test
74-
public void checkCreateAndDiscoverComponent() throws IOException, ExecutionException, InterruptedException {
75-
createComponent(project, component, feature);
76-
List<ComponentDescriptor> components = odo.discover(COMPONENT_PATH);
77-
assertNotNull(components);
78-
assertEquals(1, components.size());
79-
assertEquals(new File(COMPONENT_PATH).getAbsolutePath(), components.get(0).getPath());
80-
assertEquals(component, components.get(0).getName());
81-
}
65+
@Test
66+
public void checkCreateComponent() throws IOException, ExecutionException, InterruptedException {
67+
createComponent(project, component, feature);
68+
List<Component> components = odo.getComponents(project);
69+
assertNotNull(components);
70+
assertEquals(feature == ComponentFeature.DEV ? 1 : 0, components.size());
71+
}
8272

83-
@Test
84-
public void checkCreateAndDeleteComponent() throws IOException, ExecutionException, InterruptedException {
85-
createComponent(project, component, feature);
86-
odo.deleteComponent(project, COMPONENT_PATH, component, ComponentKind.DEVFILE);
87-
}
73+
@Test
74+
public void checkCreateAndDiscoverComponent() throws IOException, ExecutionException, InterruptedException {
75+
createComponent(project, component, feature);
76+
List<ComponentDescriptor> components = odo.discover(COMPONENT_PATH);
77+
assertNotNull(components);
78+
assertEquals(1, components.size());
79+
assertEquals(new File(COMPONENT_PATH).getAbsolutePath(), components.get(0).getPath());
80+
assertEquals(component, components.get(0).getName());
81+
}
8882

89-
@Test
90-
@Ignore
91-
public void checkCreateComponentAndLinkService() throws IOException, ExecutionException, InterruptedException {
92-
Assume.assumeTrue(feature != null);
93-
createComponent(project, component, feature);
94-
ServiceTemplate serviceTemplate = getServiceTemplate();
95-
OperatorCRD crd = getOperatorCRD(serviceTemplate);
96-
odo.createService(project, serviceTemplate, crd, service, null, true);
97-
List<Service> deployedServices = odo.getServices(project);
98-
assertNotNull(deployedServices);
99-
assertEquals(1, deployedServices.size());
100-
Service deployedService = deployedServices.get(0);
101-
assertNotNull(deployedService);
102-
Binding binding = odo.link(COMPONENT_PATH, deployedService.getKind() + "/" + deployedService.getName());
103-
assertNotNull(binding);
104-
}
83+
@Test
84+
public void checkCreateAndDeleteComponent() throws IOException, ExecutionException, InterruptedException {
85+
createComponent(project, component, feature);
86+
odo.deleteComponent(project, COMPONENT_PATH, component, ComponentKind.DEVFILE);
87+
}
10588

106-
@Test
107-
public void checkCreateComponentAndListURLs() throws IOException, ExecutionException, InterruptedException {
108-
Assume.assumeTrue(feature != null);
109-
createComponent(project, component, feature);
110-
List<URL> urls = odo.listURLs(COMPONENT_PATH);
111-
assertEquals(1, urls.size());
112-
}
89+
@Test
90+
@Ignore
91+
public void checkCreateComponentAndLinkService() throws IOException, ExecutionException, InterruptedException {
92+
Assume.assumeTrue(feature != null);
93+
createComponent(project, component, feature);
94+
ServiceTemplate serviceTemplate = getServiceTemplate();
95+
OperatorCRD crd = getOperatorCRD(serviceTemplate);
96+
odo.createService(project, serviceTemplate, crd, service, null, true);
97+
List<Service> deployedServices = odo.getServices(project);
98+
assertNotNull(deployedServices);
99+
assertEquals(1, deployedServices.size());
100+
Service deployedService = deployedServices.get(0);
101+
assertNotNull(deployedService);
102+
Binding binding = odo.link(COMPONENT_PATH, deployedService.getKind() + "/" + deployedService.getName());
103+
assertNotNull(binding);
104+
}
113105

114-
@Test
115-
public void checkCreateComponentAndDebug() throws IOException, ExecutionException, InterruptedException {
116-
Assume.assumeTrue(feature != null);
117-
createComponent(project, component, feature);
118-
odo.start(COMPONENT_PATH, component, ComponentFeature.DEV, null, null);
119-
List<URL> urls = odo.listURLs(COMPONENT_PATH);
120-
assertEquals(odo.isOpenShift() ? 2 : 1, urls.size());
121-
int debugPort;
122-
try (ServerSocket serverSocket = new ServerSocket(0)) {
123-
debugPort = serverSocket.getLocalPort();
124-
}
125-
ExecHelper.submit(() -> {
126-
try {
127-
odo.debug(COMPONENT_PATH, debugPort);
128-
DebugStatus status = odo.debugStatus(COMPONENT_PATH);
129-
assertEquals(DebugStatus.RUNNING, status);
130-
} catch (IOException e) {
131-
fail("Should not raise Exception");
132-
}
133-
});
134-
}
106+
@Test
107+
public void checkCreateComponentAndListURLs() throws IOException, ExecutionException, InterruptedException {
108+
Assume.assumeTrue(feature != null);
109+
createComponent(project, component, feature);
110+
List<URL> urls = odo.listURLs(COMPONENT_PATH);
111+
assertEquals(1, urls.size());
112+
}
135113

136-
@Test
137-
public void checkCreateComponentStarter() throws IOException, ExecutionException, InterruptedException {
138-
createProject(project);
139-
odo.createComponent("java-springboot", REGISTRY_NAME, component,
140-
Files.newTemporaryFolder().getAbsolutePath(), null, "springbootproject");
141-
List<Component> components = odo.getComponents(project);
142-
assertNotNull(components);
143-
assertEquals(0, components.size());
114+
@Test
115+
public void checkCreateComponentAndDebug() throws IOException, ExecutionException, InterruptedException {
116+
Assume.assumeTrue(feature != null);
117+
createComponent(project, component, feature);
118+
odo.start(COMPONENT_PATH, component, ComponentFeature.DEV, null, null);
119+
List<URL> urls = odo.listURLs(COMPONENT_PATH);
120+
assertEquals(odo.isOpenShift() ? 2 : 1, urls.size());
121+
int debugPort;
122+
try (ServerSocket serverSocket = new ServerSocket(0)) {
123+
debugPort = serverSocket.getLocalPort();
144124
}
125+
ExecHelper.submit(() -> {
126+
try {
127+
odo.debug(COMPONENT_PATH, debugPort);
128+
DebugStatus status = odo.debugStatus(COMPONENT_PATH);
129+
assertEquals(DebugStatus.RUNNING, status);
130+
} catch (IOException e) {
131+
fail("Should not raise Exception");
132+
}
133+
});
134+
}
135+
136+
@Test
137+
public void checkCreateComponentStarter() throws IOException, ExecutionException, InterruptedException {
138+
createProject(project);
139+
odo.createComponent("nodejs", REGISTRY_NAME, component,
140+
Files.newTemporaryFolder().getAbsolutePath(), null, "nodejs-starter");
141+
List<Component> components = odo.getComponents(project);
142+
assertNotNull(components);
143+
assertEquals(0, components.size());
144+
}
145145
}

src/it/java/org/jboss/tools/intellij/openshift/utils/odo/OdoCliTest.java

Lines changed: 80 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -33,100 +33,100 @@
3333

3434
public abstract class OdoCliTest extends BasePlatformTestCase {
3535

36-
public static final String COMPONENT_PATH = "src/it/projects/springboot-rest";
36+
public static final String COMPONENT_PATH = "src/it/projects/nodejs";
3737

38-
// see https://operatorhub.io/operator/cloud-native-postgresql/ STABLE channel for versions
39-
public static final String SERVICE_TEMPLATE = "cloud-native-postgresql.v1.16.2";
40-
public static final String SERVICE_CRD = "clusters.postgresql.k8s.enterprisedb.io";
41-
public static final String REGISTRY_URL = "https://registry.stage.devfile.io";
42-
public static final String REGISTRY_NAME = "RegistryForITTests";
38+
// see https://operatorhub.io/operator/cloud-native-postgresql/ STABLE channel for versions
39+
public static final String SERVICE_TEMPLATE = "cloud-native-postgresql.v1.16.2";
40+
public static final String SERVICE_CRD = "clusters.postgresql.k8s.enterprisedb.io";
41+
public static final String REGISTRY_URL = "https://registry.stage.devfile.io";
42+
public static final String REGISTRY_NAME = "RegistryForITTests";
4343

44-
protected Odo odo;
44+
protected Odo odo;
4545

46-
private final OdoProcessHelper processHelper = new OdoProcessHelper();
46+
private final OdoProcessHelper processHelper = new OdoProcessHelper();
4747

48-
protected Random random = new Random();
48+
protected Random random = new Random();
4949

50-
protected static final String PROJECT_PREFIX = "prj";
50+
protected static final String PROJECT_PREFIX = "prj";
5151

52-
protected static final String COMPONENT_PREFIX = "comp";
52+
protected static final String COMPONENT_PREFIX = "comp";
5353

54-
protected static final String SERVICE_PREFIX = "srv";
54+
protected static final String SERVICE_PREFIX = "srv";
5555

56-
protected static final String REGISTRY_PREFIX = "reg";
56+
protected static final String REGISTRY_PREFIX = "reg";
5757

58-
protected static final String CLUSTER_URL = System.getenv("CLUSTER_URL");
58+
protected static final String CLUSTER_URL = System.getenv("CLUSTER_URL");
5959

60-
protected static final String CLUSTER_USER = System.getenv("CLUSTER_USER");
60+
protected static final String CLUSTER_USER = System.getenv("CLUSTER_USER");
6161

62-
protected static final String CLUSTER_PASSWORD = System.getenv("CLUSTER_PASSWORD");
62+
protected static final String CLUSTER_PASSWORD = System.getenv("CLUSTER_PASSWORD");
6363

64-
private TestDialog previousTestDialog;
64+
private TestDialog previousTestDialog;
6565

66-
@Override
67-
protected void setUp() throws Exception {
68-
super.setUp();
69-
previousTestDialog = MessagesHelper.setTestDialog(TestDialog.OK);
70-
odo = getOdo().get();
71-
if (odo.listDevfileRegistries().stream().noneMatch(c -> c.getName().equals(REGISTRY_NAME)))
72-
odo.createDevfileRegistry(REGISTRY_NAME, REGISTRY_URL, null);
66+
@Override
67+
protected void setUp() throws Exception {
68+
super.setUp();
69+
previousTestDialog = MessagesHelper.setTestDialog(TestDialog.OK);
70+
odo = getOdo().get();
71+
if (odo.listDevfileRegistries().stream().noneMatch(c -> c.getName().equals(REGISTRY_NAME)))
72+
odo.createDevfileRegistry(REGISTRY_NAME, REGISTRY_URL, null);
7373

74-
if (CLUSTER_URL != null && !odo.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
75-
odo.login(CLUSTER_URL, CLUSTER_USER, CLUSTER_PASSWORD.toCharArray(), null);
76-
odo = getOdo().get();
77-
}
74+
if (CLUSTER_URL != null && !odo.getMasterUrl().toString().startsWith(CLUSTER_URL)) {
75+
odo.login(CLUSTER_URL, CLUSTER_USER, CLUSTER_PASSWORD.toCharArray(), null);
76+
odo = getOdo().get();
7877
}
79-
80-
@Override
81-
protected void tearDown() throws Exception {
82-
MessagesHelper.setTestDialog(previousTestDialog);
83-
odo.deleteDevfileRegistry(REGISTRY_NAME);
84-
super.tearDown();
85-
}
86-
87-
private CompletableFuture<Odo> getOdo() {
88-
return ToolFactory.getInstance().createOdo(getProject())
89-
.thenApply(odoDelegate -> new ApplicationRootNodeOdo(odoDelegate, mock(ApplicationsRootNode.class), processHelper));
90-
}
91-
92-
protected void createProject(String project) throws IOException, ExecutionException, InterruptedException {
93-
odo.createProject(project);
94-
odo = getOdo().get();
95-
}
96-
97-
protected void createComponent(String project, String component, ComponentFeature feature) throws IOException, ExecutionException, InterruptedException {
98-
createProject(project);
99-
cleanLocalProjectDirectory();
100-
odo.createComponent("java-springboot", REGISTRY_NAME, component,
101-
new File(COMPONENT_PATH).getAbsolutePath(), null, null);
102-
if (feature != null) {
103-
AtomicBoolean started = new AtomicBoolean();
104-
odo.start(new File(COMPONENT_PATH).getAbsolutePath(), component, feature, started::getAndSet, null);
105-
await().atMost(15, TimeUnit.MINUTES).untilTrue(started);
106-
}
107-
}
108-
109-
private void cleanLocalProjectDirectory() throws IOException {
110-
FileUtils.deleteDirectory(new File(COMPONENT_PATH, ".odo"));
111-
FileUtils.deleteDirectory(new File(COMPONENT_PATH, "kubernetes"));
112-
FileUtils.deleteQuietly(new File(COMPONENT_PATH+"/devfile.yaml"));
113-
}
114-
115-
protected OperatorCRD getOperatorCRD(ServiceTemplate serviceTemplate) {
116-
OperatorCRD crd = serviceTemplate.getCRDs().stream().filter(c -> c.getName().equals(SERVICE_CRD)).findFirst().orElse(null);
117-
assertNotNull(crd);
118-
return crd;
119-
}
120-
121-
protected ServiceTemplate getServiceTemplate() throws IOException {
122-
with().pollDelay(10, TimeUnit.SECONDS).await().atMost(10, TimeUnit.MINUTES).until(() -> !odo.getServiceTemplates().isEmpty());
123-
ServiceTemplate serviceTemplate = odo.getServiceTemplates().stream().filter(s -> s.getName().equals(SERVICE_TEMPLATE)).findFirst().orElse(null);
124-
assertNotNull(serviceTemplate);
125-
return serviceTemplate;
126-
}
127-
128-
protected void createService(String project, ServiceTemplate serviceTemplate, OperatorCRD crd, String service) throws IOException {
129-
cleanLocalProjectDirectory();
130-
odo.createService(project, serviceTemplate, crd, service, null, false);
78+
}
79+
80+
@Override
81+
protected void tearDown() throws Exception {
82+
MessagesHelper.setTestDialog(previousTestDialog);
83+
odo.deleteDevfileRegistry(REGISTRY_NAME);
84+
super.tearDown();
85+
}
86+
87+
private CompletableFuture<Odo> getOdo() {
88+
return ToolFactory.getInstance().createOdo(getProject())
89+
.thenApply(odoDelegate -> new ApplicationRootNodeOdo(odoDelegate, mock(ApplicationsRootNode.class), processHelper));
90+
}
91+
92+
protected void createProject(String project) throws IOException, ExecutionException, InterruptedException {
93+
odo.createProject(project);
94+
odo = getOdo().get();
95+
}
96+
97+
protected void createComponent(String project, String component, ComponentFeature feature) throws IOException, ExecutionException, InterruptedException {
98+
createProject(project);
99+
cleanLocalProjectDirectory();
100+
odo.createComponent("nodejs", REGISTRY_NAME, component,
101+
new File(COMPONENT_PATH).getAbsolutePath(), null, null);
102+
if (feature != null) {
103+
AtomicBoolean started = new AtomicBoolean();
104+
odo.start(new File(COMPONENT_PATH).getAbsolutePath(), component, feature, started::getAndSet, null);
105+
await().atMost(15, TimeUnit.MINUTES).untilTrue(started);
131106
}
107+
}
108+
109+
private void cleanLocalProjectDirectory() throws IOException {
110+
FileUtils.deleteDirectory(new File(COMPONENT_PATH, ".odo"));
111+
FileUtils.deleteDirectory(new File(COMPONENT_PATH, "kubernetes"));
112+
FileUtils.deleteQuietly(new File(COMPONENT_PATH + "/devfile.yaml"));
113+
}
114+
115+
protected OperatorCRD getOperatorCRD(ServiceTemplate serviceTemplate) {
116+
OperatorCRD crd = serviceTemplate.getCRDs().stream().filter(c -> c.getName().equals(SERVICE_CRD)).findFirst().orElse(null);
117+
assertNotNull(crd);
118+
return crd;
119+
}
120+
121+
protected ServiceTemplate getServiceTemplate() throws IOException {
122+
with().pollDelay(10, TimeUnit.SECONDS).await().atMost(10, TimeUnit.MINUTES).until(() -> !odo.getServiceTemplates().isEmpty());
123+
ServiceTemplate serviceTemplate = odo.getServiceTemplates().stream().filter(s -> s.getName().equals(SERVICE_TEMPLATE)).findFirst().orElse(null);
124+
assertNotNull(serviceTemplate);
125+
return serviceTemplate;
126+
}
127+
128+
protected void createService(String project, ServiceTemplate serviceTemplate, OperatorCRD crd, String service) throws IOException {
129+
cleanLocalProjectDirectory();
130+
odo.createService(project, serviceTemplate, crd, service, null, false);
131+
}
132132
}

0 commit comments

Comments
 (0)