src/test/java/com/hdekker/moondumpui/SubscriptionLinkTests.java
@Test
	public void subscriptionConfirmationLinkUpdatesDatabase() throws InterruptedException {
		
		DynamoDbAsyncClient client = DynamoDbAsyncClient.builder()
				.region(Region.of(db.getRegion()))
				.build();
	
		// add temp test subscription
		IndicatorSubscription uss = new IndicatorSubscription(
				"test-asset-sub-conf", 
				db.getAppAdminEmail(), 
				Map.of("ind", Map.of("prop1", 0.34)), 
				"testIndicatorSubscriptionLinkTests", 
				List.of("ind"), 
				"test-interface", List.of(34.00));
		
		Map<String, AttributeValue> attr = Marshalling.converter()
			.apply(uss);
		
		UUID uuid = UUID.randomUUID();
		
		HashMap<String, AttributeValue> withKeys = new HashMap<>(attr);
		withKeys.put(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION_TEMP.getPrimaryKeyValue())
						.build());
		withKeys.put(db.getSortKey(),
					AttributeValue.builder()
						.s(uuid.toString())
						.build());
		
		CompletableFuture<PutItemResponse> tempSubscriptionAddFuture = client.putItem(b->{
			
			b.tableName(db.getTableName());
			b.item(withKeys);
			
		});
		
		assertThat(tempSubscriptionAddFuture.join().sdkHttpResponse().statusCode(), Matchers.equalTo(200));
	
		// TODO create system int test to ensure email can be sent
		// and the link can be manually clicked to confirm subscription
		// for an account.
		
		// call link - offline call to check view function
		UI.getCurrent().navigate("confirm/" + uuid, QueryParameters.empty());		
		
		Thread.sleep(6000);
		
		// inspect database to see that subscription has been updated.
		// temp should be removed.
		GetItemResponse tempGetResp = client.getItem(b->{
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION_TEMP.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(uuid.toString())
						.build()));
			
		}).join();
		assertThat(tempGetResp.hasItem(), Matchers.equalTo(false));	
		
		// actual should exist.
		GetItemResponse actualGetResp = client.getItem(b->{
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(Marshalling.createSortKey().apply(uss))
						.build()));
			
		}).join();
		assertThat(actualGetResp.hasItem(), Matchers.equalTo(true));
		
		// clean up
		client.deleteItem(b->{
			
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(Marshalling.createSortKey().apply(uss))
						.build()));
			
			
		}).join();
		
		client.deleteItem(b->{
			
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION_TEMP.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(uuid.toString())
						.build()));
			
			
		}).join();
		
		
	}
/**
	 *  DynamoDB to inspect correct function of UI link
	 *  components.
	 * @throws InterruptedException 
	 * 
	 */
DynamoDB to inspect correct function of UI link
components.
DynamoDB to inspect correct function of UI link components .
@Test
	public void subscriptionConfirmationLinkUpdatesDatabase() throws InterruptedException {
		DynamoDbAsyncClient client = DynamoDbAsyncClient.builder()
				.region(Region.of(db.getRegion()))
				.build();
		IndicatorSubscription uss = new IndicatorSubscription(
				"test-asset-sub-conf", 
				db.getAppAdminEmail(), 
				Map.of("ind", Map.of("prop1", 0.34)), 
				"testIndicatorSubscriptionLinkTests", 
				List.of("ind"), 
				"test-interface", List.of(34.00));
		Map<String, AttributeValue> attr = Marshalling.converter()
			.apply(uss);
		UUID uuid = UUID.randomUUID();
		HashMap<String, AttributeValue> withKeys = new HashMap<>(attr);
		withKeys.put(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION_TEMP.getPrimaryKeyValue())
						.build());
		withKeys.put(db.getSortKey(),
					AttributeValue.builder()
						.s(uuid.toString())
						.build());
		CompletableFuture<PutItemResponse> tempSubscriptionAddFuture = client.putItem(b->{
			b.tableName(db.getTableName());
			b.item(withKeys);
		});
		assertThat(tempSubscriptionAddFuture.join().sdkHttpResponse().statusCode(), Matchers.equalTo(200));
		UI.getCurrent().navigate("confirm/" + uuid, QueryParameters.empty());		
		Thread.sleep(6000);
		GetItemResponse tempGetResp = client.getItem(b->{
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION_TEMP.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(uuid.toString())
						.build()));
		}).join();
		assertThat(tempGetResp.hasItem(), Matchers.equalTo(false));	
		GetItemResponse actualGetResp = client.getItem(b->{
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(Marshalling.createSortKey().apply(uss))
						.build()));
		}).join();
		assertThat(actualGetResp.hasItem(), Matchers.equalTo(true));
		client.deleteItem(b->{
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(Marshalling.createSortKey().apply(uss))
						.build()));
		}).join();
		client.deleteItem(b->{
			b.tableName(db.getTableName());
			b.key(Map.of(db.getPrimaryKey(),
					AttributeValue.builder()
						.s(PrimaryKeySpec.INDICATOR_SUBSCRIPTION_TEMP.getPrimaryKeyValue())
						.build(),
					db.getSortKey(),
					AttributeValue.builder()
						.s(uuid.toString())
						.build()));
		}).join();
	}
@ Test public void subscriptionConfirmationLinkUpdatesDatabase ( ) throws InterruptedException { DynamoDbAsyncClient client = DynamoDbAsyncClient . builder ( ) . region ( Region . of ( db . getRegion ( ) ) ) . build ( ) ; IndicatorSubscription uss = new IndicatorSubscription ( "test-asset-sub-conf" , db . getAppAdminEmail ( ) , Map . of ( "ind" , Map . of ( "prop1" , 0.34 ) ) , "testIndicatorSubscriptionLinkTests" , List . of ( "ind" ) , "test-interface" , List . of ( 34.00 ) ) ; Map < String , AttributeValue > attr = Marshalling . converter ( ) . apply ( uss ) ; UUID uuid = UUID . randomUUID ( ) ; HashMap < String , AttributeValue > withKeys = new HashMap < > ( attr ) ; withKeys . put ( db . getPrimaryKey ( ) , AttributeValue . builder ( ) . s ( PrimaryKeySpec . INDICATOR_SUBSCRIPTION_TEMP . getPrimaryKeyValue ( ) ) . build ( ) ) ; withKeys . put ( db . getSortKey ( ) , AttributeValue . builder ( ) . s ( uuid . toString ( ) ) . build ( ) ) ; CompletableFuture < PutItemResponse > tempSubscriptionAddFuture = client . putItem ( b -> { b . tableName ( db . getTableName ( ) ) ; b . item ( withKeys ) ; } ) ; assertThat ( tempSubscriptionAddFuture . join ( ) . sdkHttpResponse ( ) . statusCode ( ) , Matchers . equalTo ( 200 ) ) ; UI . getCurrent ( ) . navigate ( "confirm/" + uuid , QueryParameters . empty ( ) ) ; Thread . sleep ( 6000 ) ; GetItemResponse tempGetResp = client . getItem ( b -> { b . tableName ( db . getTableName ( ) ) ; b . key ( Map . of ( db . getPrimaryKey ( ) , AttributeValue . builder ( ) . s ( PrimaryKeySpec . INDICATOR_SUBSCRIPTION_TEMP . getPrimaryKeyValue ( ) ) . build ( ) , db . getSortKey ( ) , AttributeValue . builder ( ) . s ( uuid . toString ( ) ) . build ( ) ) ) ; } ) . join ( ) ; assertThat ( tempGetResp . hasItem ( ) , Matchers . equalTo ( false ) ) ; GetItemResponse actualGetResp = client . getItem ( b -> { b . tableName ( db . getTableName ( ) ) ; b . key ( Map . of ( db . getPrimaryKey ( ) , AttributeValue . builder ( ) . s ( PrimaryKeySpec . INDICATOR_SUBSCRIPTION . getPrimaryKeyValue ( ) ) . build ( ) , db . getSortKey ( ) , AttributeValue . builder ( ) . s ( Marshalling . createSortKey ( ) . apply ( uss ) ) . build ( ) ) ) ; } ) . join ( ) ; assertThat ( actualGetResp . hasItem ( ) , Matchers . equalTo ( true ) ) ; client . deleteItem ( b -> { b . tableName ( db . getTableName ( ) ) ; b . key ( Map . of ( db . getPrimaryKey ( ) , AttributeValue . builder ( ) . s ( PrimaryKeySpec . INDICATOR_SUBSCRIPTION . getPrimaryKeyValue ( ) ) . build ( ) , db . getSortKey ( ) , AttributeValue . builder ( ) . s ( Marshalling . createSortKey ( ) . apply ( uss ) ) . build ( ) ) ) ; } ) . join ( ) ; client . deleteItem ( b -> { b . tableName ( db . getTableName ( ) ) ; b . key ( Map . of ( db . getPrimaryKey ( ) , AttributeValue . builder ( ) . s ( PrimaryKeySpec . INDICATOR_SUBSCRIPTION_TEMP . getPrimaryKeyValue ( ) ) . build ( ) , db . getSortKey ( ) , AttributeValue . builder ( ) . s ( uuid . toString ( ) ) . build ( ) ) ) ; } ) . join ( ) ; }
DynamoDB to inspect correct function of UI link
  components.
DynamoDB to inspect correct function of UI link components .
// add temp test subscription // TODO create system int test to ensure email can be sent // and the link can be manually clicked to confirm subscription // for an account. // call link - offline call to check view function // inspect database to see that subscription has been updated. // temp should be removed. // actual should exist. // clean up