-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
287 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
apply plugin: 'kotlin' | ||
|
||
dependencies { | ||
implementation project(":tempest") | ||
|
||
testImplementation dep.miskAwsDynamodbTesting | ||
testImplementation dep.assertj | ||
testImplementation dep.miskTesting | ||
testImplementation dep.junitApi | ||
testImplementation dep.junitEngine | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_14 | ||
} | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions { | ||
jvmTarget = JavaVersion.VERSION_14 | ||
} | ||
} | ||
|
||
compileJava { | ||
sourceCompatibility = JavaVersion.VERSION_14 | ||
targetCompatibility = JavaVersion.VERSION_14 | ||
} | ||
|
||
tasks.withType(JavaCompile) { | ||
options.compilerArgs += "--enable-preview" | ||
} | ||
|
||
tasks.withType(Test) { | ||
jvmArgs += "--enable-preview" | ||
} | ||
|
||
tasks.withType(JavaExec) { | ||
jvmArgs += '--enable-preview' | ||
} |
31 changes: 31 additions & 0 deletions
31
samples/javarecord/src/main/java/app/cash/tempest/javarecord/Alias.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,31 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.cash.tempest.javarecord; | ||
|
||
public record Alias( | ||
String short_url, | ||
String destination_url | ||
) { | ||
public Alias.Key key() { | ||
return new Alias.Key(short_url); | ||
} | ||
|
||
public record Key( | ||
String short_url | ||
) { | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
samples/javarecord/src/main/java/app/cash/tempest/javarecord/AliasDb.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,23 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.cash.tempest.javarecord; | ||
|
||
import app.cash.tempest.LogicalDb; | ||
|
||
public interface AliasDb extends LogicalDb { | ||
AliasTable aliasTable(); | ||
} |
46 changes: 46 additions & 0 deletions
46
samples/javarecord/src/main/java/app/cash/tempest/javarecord/AliasItem.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,46 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.cash.tempest.javarecord; | ||
|
||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBAttribute; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBHashKey; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBTable; | ||
|
||
@DynamoDBTable(tableName = "j_alias_items") | ||
public class AliasItem { | ||
private String short_url; | ||
private String destination_url; | ||
|
||
@DynamoDBHashKey(attributeName = "short_url") | ||
public String getShortUrl() { | ||
return short_url; | ||
} | ||
|
||
public void setShortUrl(String short_url) { | ||
this.short_url = short_url; | ||
} | ||
|
||
@DynamoDBAttribute(attributeName = "destination_url") | ||
public String getDestinationUrl() { | ||
return destination_url; | ||
} | ||
|
||
public void setDestinationUrl(String destination_url) { | ||
this.destination_url = destination_url; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
samples/javarecord/src/main/java/app/cash/tempest/javarecord/AliasTable.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,24 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.cash.tempest.javarecord; | ||
|
||
import app.cash.tempest.InlineView; | ||
import app.cash.tempest.LogicalTable; | ||
|
||
public interface AliasTable extends LogicalTable<AliasItem> { | ||
InlineView<Alias.Key, Alias> aliases(); | ||
} |
45 changes: 45 additions & 0 deletions
45
samples/javarecord/src/test/java/app/cash/tempest/javarecord/JavaRecordTest.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,45 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.cash.tempest.javarecord; | ||
|
||
import javax.inject.Inject; | ||
import misk.testing.MiskTest; | ||
import misk.testing.MiskTestModule; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
@MiskTest(startService = true) | ||
public class JavaRecordTest { | ||
@MiskTestModule | ||
TestModule module = new TestModule(); | ||
@Inject AliasDb aliasDb; | ||
|
||
@Test | ||
public void javaLogicalTypeJavaItemType() { | ||
AliasTable aliasTable = aliasDb.aliasTable(); | ||
Alias alias = new Alias( | ||
"SquareCLA", | ||
"https://docs.google.com/forms/d/e/1FAIpQLSeRVQ35-gq2vdSxD1kdh7CJwRdjmUA0EZ9gRXaWYoUeKPZEQQ/viewform?formkey=dDViT2xzUHAwRkI3X3k5Z0lQM091OGc6MQ&ndplr=1" | ||
); | ||
aliasTable.aliases().save(alias); | ||
Alias loadedAlias = aliasTable.aliases().load(alias.key()); | ||
assertThat(loadedAlias).isNotNull(); | ||
assertThat(loadedAlias.short_url()).isEqualTo(alias.short_url()); | ||
assertThat(loadedAlias.destination_url()).isEqualTo(alias.destination_url()); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
samples/javarecord/src/test/java/app/cash/tempest/javarecord/TestModule.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,50 @@ | ||
/* | ||
* Copyright 2021 Square Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package app.cash.tempest.javarecord; | ||
|
||
import app.cash.tempest.LogicalDb; | ||
import com.amazonaws.services.dynamodbv2.AmazonDynamoDB; | ||
import com.amazonaws.services.dynamodbv2.datamodeling.DynamoDBMapper; | ||
import com.google.inject.AbstractModule; | ||
import com.google.inject.Provides; | ||
import com.google.inject.Singleton; | ||
import kotlin.jvm.internal.Reflection; | ||
import misk.MiskTestingServiceModule; | ||
import misk.aws.dynamodb.testing.DynamoDbTable; | ||
import misk.aws.dynamodb.testing.InProcessDynamoDbModule; | ||
|
||
public class TestModule extends AbstractModule { | ||
|
||
@Override protected void configure() { | ||
install(new MiskTestingServiceModule()); | ||
install( | ||
new InProcessDynamoDbModule( | ||
new DynamoDbTable( | ||
Reflection.createKotlinClass(AliasItem.class), | ||
(createTableRequest) -> createTableRequest | ||
) | ||
) | ||
); | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
AliasDb provideJAliasDb(AmazonDynamoDB amazonDynamoDB) { | ||
var dynamoDbMapper = new DynamoDBMapper(amazonDynamoDB); | ||
return LogicalDb.create(AliasDb.class, dynamoDbMapper); | ||
} | ||
} |
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
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