2626import static com .bytechef .component .brevo .constant .BrevoConstants .TO ;
2727import static org .junit .jupiter .api .Assertions .assertEquals ;
2828import static org .junit .jupiter .api .Assertions .assertNotNull ;
29+ import static org .mockito .ArgumentCaptor .forClass ;
30+ import static org .mockito .ArgumentMatchers .any ;
2931import static org .mockito .Mockito .when ;
3032
33+ import com .bytechef .component .brevo .action .BrevoSendTransactionalEmailAction .ContentType ;
3134import com .bytechef .component .definition .Context ;
3235import com .bytechef .component .definition .Context .ContextFunction ;
3336import com .bytechef .component .definition .Context .Http ;
3437import com .bytechef .component .definition .Context .Http .Body ;
38+ import com .bytechef .component .definition .Context .Http .BodyContentType ;
3539import com .bytechef .component .definition .Context .Http .Configuration ;
3640import com .bytechef .component .definition .Context .Http .Configuration .ConfigurationBuilder ;
3741import com .bytechef .component .definition .Context .Http .Executor ;
42+ import com .bytechef .component .definition .Context .Http .Response ;
3843import com .bytechef .component .definition .Context .Http .ResponseType ;
3944import com .bytechef .component .definition .Parameters ;
45+ import com .bytechef .component .definition .TypeReference ;
4046import com .bytechef .component .test .definition .MockParametersFactory ;
47+ import com .bytechef .component .test .definition .extension .MockContextSetupExtension ;
4148import java .util .List ;
4249import java .util .Map ;
4350import org .junit .jupiter .api .Test ;
51+ import org .junit .jupiter .api .extension .ExtendWith ;
4452import org .mockito .ArgumentCaptor ;
4553
4654/**
4755 * @author Marija Horvat
4856 */
49- class BrevoSendTransactionalEmailActionTest extends AbstractBrevoActionTest {
57+ @ ExtendWith (MockContextSetupExtension .class )
58+ class BrevoSendTransactionalEmailActionTest {
5059
60+ private final ArgumentCaptor <Body > bodyArgumentCaptor = forClass (Body .class );
5161 private final Parameters mockedParameters = MockParametersFactory .create (
5262 Map .of (
5363 SENDER_EMAIL , "sender@test.com" ,
5464 TO , List .of ("recepient1@test.com" , "recepient2@test.com" ),
5565 CC , List .of ("recepient1@test.com" , "recepient2@test.com" ),
5666 BCC , List .of ("recepient1@test.com" , "recepient2@test.com" ),
5767 SUBJECT , "test" ,
58- CONTENT_TYPE , BrevoSendTransactionalEmailAction . ContentType .TEXT .name (),
68+ CONTENT_TYPE , ContentType .TEXT .name (),
5969 CONTENT , "this is a test." ));
70+ private final ArgumentCaptor <String > stringArgumentCaptor = forClass (String .class );
6071
6172 @ Test
6273 void testPerform (
63- Context mockedContext , Executor mockedExecutor , Http mockedHttp ,
74+ Context mockedContext , Response mockedResponse , Executor mockedExecutor , Http mockedHttp ,
6475 ArgumentCaptor <ContextFunction <Http , Executor >> httpFunctionArgumentCaptor ,
6576 ArgumentCaptor <ConfigurationBuilder > configurationBuilderArgumentCaptor ) {
6677
6778 when (mockedHttp .post (stringArgumentCaptor .capture ()))
6879 .thenReturn (mockedExecutor );
80+ when (mockedExecutor .body (bodyArgumentCaptor .capture ()))
81+ .thenReturn (mockedExecutor );
82+ when (mockedResponse .getBody (any (TypeReference .class )))
83+ .thenReturn (Map .of ());
6984
7085 Object result = BrevoSendTransactionalEmailAction .perform (mockedParameters , null , mockedContext );
7186
72- assertEquals (responseMap , result );
73-
74- ContextFunction <Http , Executor > capturedFunction = httpFunctionArgumentCaptor .getValue ();
75-
76- assertNotNull (capturedFunction );
87+ assertEquals (Map .of (), result );
88+ assertNotNull (httpFunctionArgumentCaptor .getValue ());
7789
7890 ConfigurationBuilder configurationBuilder = configurationBuilderArgumentCaptor .getValue ();
79-
8091 Configuration configuration = configurationBuilder .build ();
8192
82- ResponseType responseType = configuration .getResponseType ();
83-
84- assertEquals (ResponseType .Type .JSON , responseType .getType ());
93+ assertEquals (ResponseType .JSON , configuration .getResponseType ());
8594 assertEquals ("/smtp/email/" , stringArgumentCaptor .getValue ());
8695
87- Body body = bodyArgumentCaptor .getValue ();
88-
8996 Map <String , Object > expectedBody = Map .of (
9097 "sender" , Map .of (EMAIL , "sender@test.com" ),
9198 TO , List .of (Map .of (EMAIL , "recepient1@test.com" ), Map .of (EMAIL , "recepient2@test.com" )),
@@ -94,6 +101,6 @@ void testPerform(
94101 SUBJECT , "test" ,
95102 "textContent" , "this is a test." );
96103
97- assertEquals (expectedBody , body . getContent ());
104+ assertEquals (Body . of ( expectedBody , BodyContentType . JSON ), bodyArgumentCaptor . getValue ());
98105 }
99106}
0 commit comments