Skip to content

Commit

Permalink
Updated tests
Browse files Browse the repository at this point in the history
  • Loading branch information
NehaNaithani committed Jan 29, 2024
1 parent 95897c2 commit 906ef92
Show file tree
Hide file tree
Showing 62 changed files with 2,540 additions and 3,135 deletions.
6 changes: 0 additions & 6 deletions iofog-agent-daemon/build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id 'jacoco'
// id "org.jetbrains.kotlin.jvm" version "1.9.22"
}

description = 'iofog-agent-daemon'
Expand All @@ -13,7 +12,6 @@ dependencies {
implementation 'com.jcraft:jsch:0.1.55'
implementation 'com.fasterxml.jackson.core:jackson-databind:2.15.1'
implementation 'org.apache.httpcomponents:httpmime:4.5.7'
// implementation 'junit:junit:4.13.2'
implementation 'org.junit.jupiter:junit-jupiter-api:5.10.0'
implementation 'com.github.oshi:oshi-core:6.4.0'
implementation 'org.slf4j:slf4j-nop:2.0.7'
Expand All @@ -27,10 +25,6 @@ dependencies {
testImplementation 'org.junit.jupiter:junit-jupiter:5.10.0'
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
testImplementation 'org.testng:testng:7.7.0'
// testImplementation 'org.powermock:powermock-module-junit4-rule:2.0.9'
// testImplementation 'org.powermock:powermock-module-junit4:2.0.9'
// testImplementation 'org.powermock:powermock-api-mockito2:2.0.9'
// testImplementation 'org.powermock:powermock-core:2.0.9'
}

processResources {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public int getCode() {
* common type for popular arm architectures:
* arm, arm32, aarch64, armv{VERSION}{CODE}
*/
ARM("^(arm|arm32|armv[0-9]+.*|aarch64)$") {
ARM("^(arm|arm32|arm64|armv[0-9]+.*|aarch64)$") {
@Override
public int getCode() {
return 2;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -80,7 +80,6 @@ public void setup() {
.thenReturn(new HashMap<>())
.thenThrow(new Exception("item not found or defined more than once"));

// CommandProperties mock
Mockito.when(CmdProperties.getVersion()).thenReturn("1.2.2");
Mockito.when(CmdProperties.getVersionMessage()).thenReturn(version);
Mockito.when(CmdProperties.getDeprovisionMessage()).thenReturn("Deprovisioning from controller ... %s");
Expand Down Expand Up @@ -108,7 +107,6 @@ public void tearDown() throws Exception {
@Test
public void testGetKeys() {
Assertions.assertFalse(CommandLineAction.HELP_ACTION.getKeys().isEmpty());
// Assertions.assertTrue(isEqual(stop, CommandLineAction.getActionByKey("stop").getKeys()));
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.eclipse.iofog.command_line.util;
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -29,23 +29,18 @@
*/
@ExtendWith(MockitoExtension.class)
public class CommandShellExecutorTest {
private static CommandShellExecutor commandShellExecutor;
private CommandShellResultSet<List<String>, List<String>> commandShellResultSet;
private String command;
List<String> value;
List<String> errors;

@BeforeAll
public static void setUp() throws Exception {
commandShellExecutor = spy(new CommandShellExecutor());
spy(new CommandShellExecutor());
}

@AfterAll
public static void tearDown() throws Exception {
// command = null;
// value = null;
// errors = null;
// commandShellResultSet = null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -55,7 +55,6 @@ public class ImageDownloadManagerTest {
@Mock
private static DockerUtil dockerUtil;
private static String microserviceUuid;
private static DockerClient dockerClient;
private static MockedStatic<CommandShellExecutor> cmdShellExecutor;
private static Container container;
private static CommandShellResultSet<List<String>, List<String>> resultSetWithPath;
Expand All @@ -69,19 +68,8 @@ public class ImageDownloadManagerTest {
public void setUp() throws Exception {
cmdShellExecutor = mockStatic(CommandShellExecutor.class);
microserviceUuid = "microservice-id";
// mockStatic(Configuration.class);
// when(Configuration.getDockerUrl()).thenReturn("unix://dockerUrl/");
// when(Configuration.getDockerApiVersion()).thenReturn("19.03.1");
orchestrator = mock(Orchestrator.class);
mock(DefaultDockerClientConfig.class);
// DockerClientBuilder dockerClientBuilder = mock(DockerClientBuilder.class);
// mockStatic(DockerClientBuilder.class);

// dockerClient = mock(DockerClient.class);
// mockStatic(DockerClient.class);
// when(DockerClientBuilder.getInstance(any(DefaultDockerClientConfig.class))).thenReturn(dockerClientBuilder);
// when(dockerClientBuilder.build()).thenReturn(dockerClient);
// dockerUtil = mock(DockerUtil.class);
dockerUtilStatic = mockStatic(DockerUtil.class);
container = mock(Container.class);
when(DockerUtil.getInstance()).thenReturn(dockerUtil);
Expand All @@ -94,13 +82,6 @@ public void setUp() throws Exception {
when(dockerUtil.getContainer(microserviceUuid)).thenReturn(Optional.of(container));
cmdShellExecutor.when(() -> CommandShellExecutor.executeCommand(any()))
.thenReturn(resultSetWithPath);
// cmdShellExecutor.when(CommandShellExecutor::executeCommand(any())).thenReturn(resultSetWithPath);

// error = new ArrayList<>();
// value = new ArrayList<>();
// value.add("local/path/newFile");
// resultSetWithPath = new CommandShellResultSet<>(value, error);
// when(CommandShellExecutor.executeCommand(any())).thenReturn(resultSetWithPath);
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Expand All @@ -116,8 +97,6 @@ public void tearDown() throws Exception {
value = null;
resultSetWithPath = null;
MODULE_NAME = null;
// dockerClient.close();
// reset(dockerClientBuilder);
cmdShellExecutor.close();
reset(dockerUtil);
dockerUtilStatic.close();
Expand Down Expand Up @@ -146,7 +125,6 @@ public void createImageSnapshotWhenCommandExecuteReturnsSuccess() throws Excepti
verify(dockerUtil, atLeastOnce()).getContainer(microserviceUuid);
verify(orchestrator, atLeastOnce()).sendFileToController(any(), any());
Mockito.verify(LoggingService.class, atLeastOnce());
// LoggingService.logInfo(MODULE_NAME, "Image snapshot deleted");
LoggingService.logDebug(MODULE_NAME, "Finished Create image snapshot");
}

Expand Down Expand Up @@ -177,16 +155,9 @@ public void createImageSnapshotWhenCommandExecuteReturnsError() throws Exception
*/
@Test
public void createImageSnapshotWhenCommandExecuteReturnsEmpty() throws Exception {
// error = new ArrayList<>();
// value = new ArrayList<>();
// resultSetWithPath = new CommandShellResultSet<>(value, error);
when(dockerUtil.getContainer(microserviceUuid)).thenReturn(Optional.of(container));
// when(CommandShellExecutor.executeCommand(any())).thenReturn(resultSetWithPath);
ImageDownloadManager.createImageSnapshot(orchestrator, microserviceUuid);
verify(dockerUtil, atLeastOnce()).getContainer(microserviceUuid);
// verify(orchestrator, never()).sendFileToController(any(), any());
// Mockito.verify(LoggingService.class);
// LoggingService.logDebug(MODULE_NAME, "Finished Create image snapshot");
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down Expand Up @@ -90,7 +90,6 @@ public void setUp() throws Exception {
@AfterEach
public void tearDown() throws Exception {
commandShellExecutor.close();
// reset(CommandShellExecutor.class);
loggingService.close();
reset(iterator);
microserviceUuid = null;
Expand Down Expand Up @@ -151,10 +150,6 @@ public void throwsIllegalExceptionWhenPidByContainerNameIsNotFound() {
straceDiagnosticManager.updateMonitoringMicroservices(jsonObject);
verify(jsonObject, times(1)).getJsonArray("straceValues");
verify(iterator, atLeastOnce()).hasNext();
// verify(microserviceObject, atLeastOnce()).getString("microserviceUuid");
// verify(microserviceObject, atLeastOnce()).getBoolean("straceRun");
// CommandShellExecutor.executeCommand(any());
// verify(CommandShellExecutor.class, times(1));
verify(LoggingService.class, times(1));
LoggingService.logError(any(), any(), any());
}
Expand Down Expand Up @@ -302,18 +297,6 @@ public void testDisableMicroserviceStraceDiagnosticsWhenMicroserviceUuidIsPresen
assertEquals(1, straceDiagnosticManager.getMonitoringMicroservices().size());
}

/**
* Test disableMicroserviceStraceDiagnostics with microserviceUuid which is not present
*/
// @Test
// public void testDisableMicroserviceStraceDiagnosticsWhenMicroserviceUuidIsNotPresent() {
// microserviceStraceData = new MicroserviceStraceData("newMicroserviceUuid", 1234, true);
// straceDiagnosticManager.getMonitoringMicroservices().add(microserviceStraceData);
// straceDiagnosticManager.disableMicroserviceStraceDiagnostics("Uuid");
// assertEquals(0, straceDiagnosticManager.getMonitoringMicroservices().size());
//
// }

/**
* Test disableMicroserviceStraceDiagnostics with microserviceUuid null
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* *******************************************************************************
* * Copyright (c) 2018-2022 Edgeworx, Inc.
* * Copyright (c) 2018-2024 Edgeworx, Inc.
* *
* * This program and the accompanying materials are made available under the
* * terms of the Eclipse Public License v. 2.0 which is available at
Expand Down
Loading

0 comments on commit 906ef92

Please sign in to comment.