Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,16 @@ jobs:
cache: maven

- name: Run tests with Maven
run: mvn -B test --file pom.xml
env:
TEST_COGNITO_USER_POOL_ID: ${{ secrets.TEST_COGNITO_USER_POOL_ID }}
TEST_COGNITO_CLIENT_ID: ${{ secrets.TEST_COGNITO_CLIENT_ID }}
TEST_COGNITO_USERNAME: ${{ secrets.TEST_COGNITO_USERNAME }}
TEST_COGNITO_PASSWORD: ${{ secrets.TEST_COGNITO_PASSWORD }}
run: >
mvn -B test --file pom.xml

- name: Generate test report
run: >
mvn -B
site -DgenerateReports=false
surefire-report:report-only
27 changes: 26 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
# MoC Java
MoC client for Java

[![Java CI with Maven](https://github.com/makeOurCity/moc-java/actions/workflows/test.yml/badge.svg)](https://github.com/makeOurCity/moc-java/actions/workflows/test.yml)
[![Java CI with Maven](https://github.com/makeOurCity/moc-java/actions/workflows/test.yml/badge.svg)](https://github.com/makeOurCity/moc-java/actions/workflows/test.yml)


# Development

## Testing

Set `.vscode/settings` env

```json
{
"java.test.config": {
"env": {
"TEST_COGNITO_USER_POOL_ID": "",
"TEST_COGNITO_CLIENT_ID": "",
"TEST_COGNITO_USERNAME": "",
"TEST_COGNITO_PASSWORD": ""
}
}
}
```

```console
$ mvn clean install
$ mvn teset
```
14 changes: 9 additions & 5 deletions src/test/java/city/makeour/moc/FetchCognitoTokenTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
import org.springframework.context.annotation.Description;

class FetchCognitoTokenTest {

// TODO: テストのスキップについてきちんと動作確認をする。
@Test
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USER_POOL_ID", matches = ".+")
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_CLIENT_ID", matches = ".+")
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USERNAME", matches = ".+")
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_PASSWORD", matches = ".+")
@Description("Cognitoのトークンを取得するテスト")
@EnabledIfEnvironmentVariables({
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USER_POOL_ID", matches = ".*"),
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_CLIENT_ID", matches = ".*"),
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USERNAME", matches = ".*"),
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_PASSWORD", matches = ".*")
})
public void testFetchTokenWithSrpAuth() throws Exception {
String cognitoUserPoolId = System.getenv("TEST_COGNITO_USER_POOL_ID");
String cognitoClientId = System.getenv("TEST_COGNITO_CLIENT_ID");
Expand Down
36 changes: 35 additions & 1 deletion src/test/java/city/makeour/moc/MocClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,18 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

import java.security.GeneralSecurityException;
import java.security.NoSuchAlgorithmException;
import java.util.List;
import java.util.UUID;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;

import city.makeour.ngsi.v2.api.EntitiesApi;
import city.makeour.ngsi.v2.model.CreateEntityRequest;
import city.makeour.ngsi.v2.model.ListEntitiesResponse;

class MocClientTest {
Expand Down Expand Up @@ -52,4 +58,32 @@ void testEntitiesApi() {
assertNotNull(list);
System.out.println("Entities: " + list);
}
}

@Test
@DisplayName("ログインしてデータ作成できるかのテスト")
@EnabledIfEnvironmentVariables({
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USER_POOL_ID", matches = ".*"),
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_CLIENT_ID", matches = ".*"),
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_USERNAME", matches = ".*"),
@EnabledIfEnvironmentVariable(named = "TEST_COGNITO_PASSWORD", matches = ".*")
})
void testSetMocAuthInfo() throws GeneralSecurityException, NoSuchAlgorithmException {
String cognitoUserPoolId = System.getenv("TEST_COGNITO_USER_POOL_ID");
String cognitoClientId = System.getenv("TEST_COGNITO_CLIENT_ID");
String username = System.getenv("TEST_COGNITO_USERNAME");
String password = System.getenv("TEST_COGNITO_PASSWORD");

MocClient client = new MocClient();
client.setMocAuthInfo(cognitoUserPoolId, cognitoClientId);
client.login(username, password);

String uuid = UUID.randomUUID().toString();

CreateEntityRequest entity = new CreateEntityRequest();
entity.setType("TestEntity");
entity.setId("urn:ngsi-ld:TestEntity:" + uuid);

client.entities().createEntity("application/json", entity, "keyValues");

}
}