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.
[PAGOPA-1075] feat: add enhancement for /info API
- Loading branch information
1 parent
001c93d
commit ec8f899
Showing
4 changed files
with
135 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package it.gov.pagopa.reporting.models; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import lombok.*; | ||
|
||
@Data | ||
@Builder(toBuilder = true) | ||
@NoArgsConstructor | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
public class AppInfo { | ||
|
||
private String name; | ||
private String version; | ||
private String environment; | ||
} |
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,88 @@ | ||
package it.gov.pagopa.reporting; | ||
|
||
import com.microsoft.azure.functions.ExecutionContext; | ||
import com.microsoft.azure.functions.HttpRequestMessage; | ||
import com.microsoft.azure.functions.HttpResponseMessage; | ||
import com.microsoft.azure.functions.HttpStatus; | ||
import it.gov.pagopa.reporting.models.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 java.util.Optional; | ||
import java.util.logging.Logger; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.doReturn; | ||
import static org.mockito.Mockito.mock; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class InfoTest { | ||
|
||
@Mock | ||
ExecutionContext context; | ||
|
||
@Spy | ||
Info infoFunction; | ||
|
||
@Test | ||
void runOK() { | ||
// 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("example-test-logger"); | ||
String path = "/META-INF/maven/it.gov.pagopa.reporting/reporting-batch/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("example-test-logger"); | ||
String path = "/META-INF/maven/it.gov.pagopa.reporting/reporting-batch/fake"; | ||
|
||
// Execute function | ||
AppInfo response = infoFunction.getInfo(logger, path); | ||
|
||
// Checking assertions | ||
assertNull(response.getName()); | ||
assertNull(response.getVersion()); | ||
assertNotNull(response.getEnvironment()); | ||
} | ||
|
||
} |
5 changes: 5 additions & 0 deletions
5
src/test/resources/META-INF/maven/it.gov.pagopa.reporting/reporting-batch/pom.properties
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,5 @@ | ||
#Generated by Maven | ||
#Fri Jul 07 10:12:25 CEST 2023 | ||
artifactId=reporting-batch | ||
groupId=it.gov.pagopa.reporting | ||
version=x.y.z |