Skip to content

Commit 998de49

Browse files
monikakusterivicac
authored andcommitted
2040 SF
1 parent 385e17e commit 998de49

7 files changed

Lines changed: 89 additions & 175 deletions

File tree

server/libs/modules/components/brevo/src/main/java/com/bytechef/component/brevo/action/BrevoUpdateContactAction.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@
2222
import static com.bytechef.component.definition.ComponentDsl.action;
2323
import static com.bytechef.component.definition.ComponentDsl.string;
2424
import static com.bytechef.component.definition.Context.Http.Body;
25-
import static com.bytechef.component.definition.Context.Http.responseType;
2625

2726
import com.bytechef.component.brevo.util.BrevoUtils;
2827
import com.bytechef.component.definition.ActionDefinition.OptionsFunction;
2928
import com.bytechef.component.definition.ComponentDsl.ModifiableActionDefinition;
3029
import com.bytechef.component.definition.Context;
31-
import com.bytechef.component.definition.Context.Http;
3230
import com.bytechef.component.definition.Parameters;
3331

3432
/**
@@ -68,7 +66,6 @@ public static Object perform(Parameters inputParameters, Parameters connectionPa
6866
FIRST_NAME, inputParameters.getString(FIRST_NAME),
6967
LAST_NAME, inputParameters.getString(LAST_NAME)
7068
}))
71-
.configuration(responseType(Http.ResponseType.JSON))
7269
.execute();
7370

7471
return null;

server/libs/modules/components/brevo/src/test/java/com/bytechef/component/brevo/action/AbstractBrevoActionTest.java

Lines changed: 0 additions & 50 deletions
This file was deleted.

server/libs/modules/components/brevo/src/test/java/com/bytechef/component/brevo/action/BrevoCreateContactActionTest.java

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -21,60 +21,67 @@
2121
import static com.bytechef.component.brevo.constant.BrevoConstants.LAST_NAME;
2222
import static org.junit.jupiter.api.Assertions.assertEquals;
2323
import static org.junit.jupiter.api.Assertions.assertNotNull;
24+
import static org.mockito.ArgumentCaptor.forClass;
25+
import static org.mockito.ArgumentMatchers.any;
2426
import static org.mockito.Mockito.when;
2527

2628
import com.bytechef.component.definition.Context;
2729
import com.bytechef.component.definition.Context.ContextFunction;
2830
import com.bytechef.component.definition.Context.Http;
2931
import com.bytechef.component.definition.Context.Http.Body;
32+
import com.bytechef.component.definition.Context.Http.BodyContentType;
3033
import com.bytechef.component.definition.Context.Http.Configuration;
3134
import com.bytechef.component.definition.Context.Http.Configuration.ConfigurationBuilder;
3235
import com.bytechef.component.definition.Context.Http.Executor;
36+
import com.bytechef.component.definition.Context.Http.Response;
3337
import com.bytechef.component.definition.Context.Http.ResponseType;
3438
import com.bytechef.component.definition.Parameters;
39+
import com.bytechef.component.definition.TypeReference;
3540
import com.bytechef.component.test.definition.MockParametersFactory;
41+
import com.bytechef.component.test.definition.extension.MockContextSetupExtension;
3642
import java.util.Map;
3743
import org.junit.jupiter.api.Test;
44+
import org.junit.jupiter.api.extension.ExtendWith;
3845
import org.mockito.ArgumentCaptor;
3946

4047
/**
4148
* @author Marija Horvat
4249
*/
43-
class BrevoCreateContactActionTest extends AbstractBrevoActionTest {
50+
@ExtendWith(MockContextSetupExtension.class)
51+
class BrevoCreateContactActionTest {
4452

53+
private final ArgumentCaptor<Body> bodyArgumentCaptor = forClass(Body.class);
4554
private final Parameters mockedParameters = MockParametersFactory.create(
4655
Map.of(EMAIL, "test@test.com", FIRST_NAME, "test", LAST_NAME, "test"));
56+
private final ArgumentCaptor<String> stringArgumentCaptor = forClass(String.class);
4757

4858
@Test
4959
void testPerform(
50-
Context mockedContext, Executor mockedExecutor, Http mockedHttp,
60+
Context mockedContext, Response mockedResponse, Executor mockedExecutor, Http mockedHttp,
5161
ArgumentCaptor<ContextFunction<Http, Executor>> httpFunctionArgumentCaptor,
5262
ArgumentCaptor<ConfigurationBuilder> configurationBuilderArgumentCaptor) {
5363

5464
when(mockedHttp.post(stringArgumentCaptor.capture()))
5565
.thenReturn(mockedExecutor);
66+
when(mockedExecutor.body(bodyArgumentCaptor.capture()))
67+
.thenReturn(mockedExecutor);
68+
when(mockedResponse.getBody(any(TypeReference.class)))
69+
.thenReturn(Map.of());
5670

5771
Object result = BrevoCreateContactAction.perform(mockedParameters, null, mockedContext);
5872

59-
assertEquals(responseMap, result);
60-
61-
ContextFunction<Http, Executor> capturedFunction = httpFunctionArgumentCaptor.getValue();
62-
63-
assertNotNull(capturedFunction);
73+
assertEquals(Map.of(), result);
74+
assertNotNull(httpFunctionArgumentCaptor.getValue());
6475

6576
ConfigurationBuilder configurationBuilder = configurationBuilderArgumentCaptor.getValue();
66-
6777
Configuration configuration = configurationBuilder.build();
6878

69-
ResponseType responseType = configuration.getResponseType();
70-
71-
assertEquals(ResponseType.Type.JSON, responseType.getType());
79+
assertEquals(ResponseType.JSON, configuration.getResponseType());
7280
assertEquals("/contacts/", stringArgumentCaptor.getValue());
73-
74-
Body body = bodyArgumentCaptor.getValue();
75-
Map<String, Object> expected = Map.of(
76-
EMAIL, "test@test.com",
77-
"attributes", Map.of(FIRST_NAME, "test", LAST_NAME, "test"));
78-
assertEquals(expected, body.getContent());
81+
assertEquals(
82+
Body.of(
83+
Map.of(EMAIL, "test@test.com", "attributes", Map.of(FIRST_NAME, "test", LAST_NAME, "test")),
84+
BodyContentType.JSON),
85+
bodyArgumentCaptor.getValue());
7986
}
8087
}

server/libs/modules/components/brevo/src/test/java/com/bytechef/component/brevo/action/BrevoSendTransactionalEmailActionTest.java

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,66 +26,73 @@
2626
import static com.bytechef.component.brevo.constant.BrevoConstants.TO;
2727
import static org.junit.jupiter.api.Assertions.assertEquals;
2828
import static org.junit.jupiter.api.Assertions.assertNotNull;
29+
import static org.mockito.ArgumentCaptor.forClass;
30+
import static org.mockito.ArgumentMatchers.any;
2931
import static org.mockito.Mockito.when;
3032

33+
import com.bytechef.component.brevo.action.BrevoSendTransactionalEmailAction.ContentType;
3134
import com.bytechef.component.definition.Context;
3235
import com.bytechef.component.definition.Context.ContextFunction;
3336
import com.bytechef.component.definition.Context.Http;
3437
import com.bytechef.component.definition.Context.Http.Body;
38+
import com.bytechef.component.definition.Context.Http.BodyContentType;
3539
import com.bytechef.component.definition.Context.Http.Configuration;
3640
import com.bytechef.component.definition.Context.Http.Configuration.ConfigurationBuilder;
3741
import com.bytechef.component.definition.Context.Http.Executor;
42+
import com.bytechef.component.definition.Context.Http.Response;
3843
import com.bytechef.component.definition.Context.Http.ResponseType;
3944
import com.bytechef.component.definition.Parameters;
45+
import com.bytechef.component.definition.TypeReference;
4046
import com.bytechef.component.test.definition.MockParametersFactory;
47+
import com.bytechef.component.test.definition.extension.MockContextSetupExtension;
4148
import java.util.List;
4249
import java.util.Map;
4350
import org.junit.jupiter.api.Test;
51+
import org.junit.jupiter.api.extension.ExtendWith;
4452
import 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
}

server/libs/modules/components/brevo/src/test/java/com/bytechef/component/brevo/action/BrevoUpdateContactActionTest.java

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,60 +22,51 @@
2222
import static org.junit.jupiter.api.Assertions.assertEquals;
2323
import static org.junit.jupiter.api.Assertions.assertNotNull;
2424
import static org.junit.jupiter.api.Assertions.assertNull;
25+
import static org.mockito.ArgumentCaptor.forClass;
2526
import static org.mockito.Mockito.when;
2627

2728
import com.bytechef.component.definition.Context;
2829
import com.bytechef.component.definition.Context.ContextFunction;
2930
import com.bytechef.component.definition.Context.Http;
3031
import com.bytechef.component.definition.Context.Http.Body;
31-
import com.bytechef.component.definition.Context.Http.Configuration;
32-
import com.bytechef.component.definition.Context.Http.Configuration.ConfigurationBuilder;
32+
import com.bytechef.component.definition.Context.Http.BodyContentType;
3333
import com.bytechef.component.definition.Context.Http.Executor;
34-
import com.bytechef.component.definition.Context.Http.ResponseType;
3534
import com.bytechef.component.definition.Parameters;
3635
import com.bytechef.component.test.definition.MockParametersFactory;
36+
import com.bytechef.component.test.definition.extension.MockContextSetupExtension;
3737
import java.util.Map;
3838
import org.junit.jupiter.api.Test;
39+
import org.junit.jupiter.api.extension.ExtendWith;
3940
import org.mockito.ArgumentCaptor;
4041

4142
/**
4243
* @author Marija Horvat
4344
*/
44-
class BrevoUpdateContactActionTest extends AbstractBrevoActionTest {
45+
@ExtendWith(MockContextSetupExtension.class)
46+
class BrevoUpdateContactActionTest {
4547

48+
private final ArgumentCaptor<Body> bodyArgumentCaptor = forClass(Body.class);
4649
private final Parameters mockedParameters = MockParametersFactory.create(
4750
Map.of(EMAIL, "test@test.com", FIRST_NAME, "test", LAST_NAME, "test"));
51+
private final ArgumentCaptor<String> stringArgumentCaptor = forClass(String.class);
4852

4953
@Test
5054
void testPerform(
5155
Context mockedContext, Executor mockedExecutor, Http mockedHttp,
52-
ArgumentCaptor<ContextFunction<Http, Executor>> httpFunctionArgumentCaptor,
53-
ArgumentCaptor<ConfigurationBuilder> configurationBuilderArgumentCaptor) {
56+
ArgumentCaptor<ContextFunction<Http, Executor>> httpFunctionArgumentCaptor) {
5457

5558
when(mockedHttp.put(stringArgumentCaptor.capture()))
5659
.thenReturn(mockedExecutor);
60+
when(mockedExecutor.body(bodyArgumentCaptor.capture()))
61+
.thenReturn(mockedExecutor);
5762

5863
Object result = BrevoUpdateContactAction.perform(mockedParameters, null, mockedContext);
5964

6065
assertNull(result);
61-
62-
ContextFunction<Http, Executor> capturedFunction = httpFunctionArgumentCaptor.getValue();
63-
64-
assertNotNull(capturedFunction);
65-
66-
ConfigurationBuilder configurationBuilder = configurationBuilderArgumentCaptor.getValue();
67-
68-
Configuration configuration = configurationBuilder.build();
69-
70-
ResponseType responseType = configuration.getResponseType();
71-
72-
assertEquals(ResponseType.Type.JSON, responseType.getType());
66+
assertNotNull(httpFunctionArgumentCaptor.getValue());
7367
assertEquals("/contacts/test@test.com", stringArgumentCaptor.getValue());
74-
75-
Body body = bodyArgumentCaptor.getValue();
76-
77-
Map<String, Object> expectedMap = Map.of("attributes", Map.of(FIRST_NAME, "test", LAST_NAME, "test"));
78-
79-
assertEquals(expectedMap, body.getContent());
68+
assertEquals(
69+
Body.of(Map.of("attributes", Map.of(FIRST_NAME, "test", LAST_NAME, "test")), BodyContentType.JSON),
70+
bodyArgumentCaptor.getValue());
8071
}
8172
}

0 commit comments

Comments
 (0)