|
| 1 | +package scenarios; |
| 2 | + |
| 3 | +import com.example.bedrockruntime.scenario.BedrockActions; |
| 4 | +import com.example.bedrockruntime.scenario.WeatherTool; |
| 5 | +import org.junit.jupiter.api.*; |
| 6 | +import software.amazon.awssdk.services.bedrockruntime.model.ContentBlock; |
| 7 | +import software.amazon.awssdk.services.bedrockruntime.model.ConversationRole; |
| 8 | +import software.amazon.awssdk.services.bedrockruntime.model.ConverseResponse; |
| 9 | +import software.amazon.awssdk.services.bedrockruntime.model.Message; |
| 10 | +import java.util.ArrayList; |
| 11 | +import java.util.List; |
| 12 | + |
| 13 | + |
| 14 | +import static org.junit.jupiter.api.Assertions.*; |
| 15 | + |
| 16 | +@TestInstance(TestInstance.Lifecycle.PER_METHOD) |
| 17 | +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) |
| 18 | +public class TestBedrockTool { |
| 19 | + private static String prompt = "How is the weather in New York"; |
| 20 | + static BedrockActions bedrockActions = new BedrockActions(); |
| 21 | + private static WeatherTool weatherTool = new WeatherTool(); |
| 22 | + private static String modelId = "anthropic.claude-3-sonnet-20240229-v1:0"; |
| 23 | + |
| 24 | + @Test |
| 25 | + @Tag("IntegrationTest") |
| 26 | + @Order(1) |
| 27 | + public void testCreateAssetModel() { |
| 28 | + List<Message> conversation = new ArrayList<>(); |
| 29 | + ContentBlock block = ContentBlock.builder() |
| 30 | + .text(prompt) |
| 31 | + .build(); |
| 32 | + |
| 33 | + List<ContentBlock> blockList = new ArrayList<>(); |
| 34 | + blockList.add(block); |
| 35 | + |
| 36 | + Message message = Message.builder() |
| 37 | + .role(ConversationRole.USER) |
| 38 | + .content(blockList) |
| 39 | + .build(); |
| 40 | + |
| 41 | + conversation.add(message); |
| 42 | + ConverseResponse bedrockResponse = bedrockActions.sendConverseRequestAsync(modelId, prompt, conversation, weatherTool.getToolSpec()); |
| 43 | + |
| 44 | + // Assertions |
| 45 | + assertNotNull(bedrockResponse, "Response should not be null"); |
| 46 | + assertNotNull(bedrockResponse.output().message(), "Output text should not be null"); |
| 47 | + System.out.println("Test 1 passed"); |
| 48 | + } |
| 49 | +} |
| 50 | + |
0 commit comments