generated from pagopa/pagopa-functions-template
-
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.
Merge pull request #4 from pagopa/NOD-566-adeguamento-pipeline-code-r…
…eview [NOD-566] feat: added JUnit tests
- Loading branch information
Showing
15 changed files
with
462 additions
and
78 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
18 changes: 0 additions & 18 deletions
18
src/main/java/it/gov/pagopa/nodoverifykototablestorage/exception/AppException.java
This file was deleted.
Oops, something went wrong.
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
91 changes: 91 additions & 0 deletions
91
src/test/java/it/gov/pagopa/nodoverifykototablestorage/InfoTest.java
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,91 @@ | ||
package it.gov.pagopa.nodoverifykototablestorage; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.*; | ||
|
||
import java.util.Optional; | ||
import java.util.logging.Logger; | ||
|
||
import it.gov.pagopa.nodoverifykototablestorage.util.AppInfo; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Spy; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import com.microsoft.azure.functions.ExecutionContext; | ||
import com.microsoft.azure.functions.HttpRequestMessage; | ||
import com.microsoft.azure.functions.HttpResponseMessage; | ||
import com.microsoft.azure.functions.HttpStatus; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class InfoTest { | ||
|
||
@Mock | ||
ExecutionContext context; | ||
|
||
@Spy | ||
Info infoFunction; | ||
|
||
@Test | ||
void runHttpTriggerOK() { | ||
// test precondition | ||
Logger logger = Logger.getLogger("NodoVerifyKOEventToTableStorage-test-logger"); | ||
when(context.getLogger()).thenReturn(logger); | ||
|
||
// test precondition | ||
final HttpResponseMessage.Builder builder = mock(HttpResponseMessage.Builder.class); | ||
@SuppressWarnings("unchecked") | ||
HttpRequestMessage<Optional<String>> request = mock(HttpRequestMessage.class); | ||
|
||
HttpResponseMessage responseMock = mock(HttpResponseMessage.class); | ||
doReturn(HttpStatus.OK).when(responseMock).getStatus(); | ||
doReturn(builder).when(builder).body(any()); | ||
doReturn(responseMock).when(builder).build(); | ||
doReturn(builder).when(request).createResponseBuilder(any(HttpStatus.class)); | ||
doReturn(builder).when(builder).header(anyString(), anyString()); | ||
|
||
// test execution | ||
HttpResponseMessage response = infoFunction.run(request, context); | ||
|
||
// test assertion | ||
assertEquals(HttpStatus.OK, response.getStatus()); | ||
} | ||
|
||
@SneakyThrows | ||
@Test | ||
void getInfoOk() { | ||
|
||
// Mocking service creation | ||
Logger logger = Logger.getLogger("NodoVerifyKOEventToTableStorage-test-logger"); | ||
String path = "/META-INF/maven/it.gov.pagopa/nodoverifykototablestorage/pom.properties"; | ||
|
||
// Execute function | ||
AppInfo response = infoFunction.getInfo(logger, path); | ||
|
||
// Checking assertions | ||
assertNotNull(response.getName()); | ||
assertNotNull(response.getVersion()); | ||
assertNotNull(response.getEnvironment()); | ||
} | ||
|
||
@SneakyThrows | ||
@Test | ||
void getInfoKo() { | ||
|
||
// Mocking service creation | ||
Logger logger = Logger.getLogger("NodoVerifyKOEventToTableStorage-test-logger"); | ||
|
||
// Execute function | ||
AppInfo response = infoFunction.getInfo(logger, null); | ||
|
||
// Checking assertions | ||
assertNull(response.getName()); | ||
assertNull(response.getVersion()); | ||
assertNotNull(response.getEnvironment()); | ||
} | ||
|
||
} |
Oops, something went wrong.