Skip to content

Commit 3ea5738

Browse files
committed
2785 - SF
1 parent 03a0202 commit 3ea5738

File tree

5 files changed

+56
-67
lines changed

5 files changed

+56
-67
lines changed

server/libs/modules/components/amplitude/src/main/java/com/bytechef/component/amplitude/action/AmplitudeCreateAttributionEventAction.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.bytechef.component.definition.Context.Http.ResponseType;
3939
import com.bytechef.component.definition.OptionsDataSource.ActionOptionsFunction;
4040
import com.bytechef.component.definition.Parameters;
41-
import com.bytechef.component.definition.TypeReference;
4241

4342
/**
4443
* @author Nikolina Spehar
@@ -67,8 +66,9 @@ public class AmplitudeCreateAttributionEventAction {
6766
.properties(
6867
string(KEY)
6968
.label("Identifier Key")
70-
.description("For iOS input the Identifier for Advertiser or the Identifier for Vendor." +
71-
"For Android input the Google ADID or App Set ID")
69+
.description(
70+
"For iOS input the Identifier for Advertiser or the Identifier for Vendor.For Android " +
71+
"input the Google ADID or App Set ID.")
7272
.options((ActionOptionsFunction<String>) AmplitudeUtils::getIdentifierKeyOptions)
7373
.optionsLookupDependsOn(PLATFORM)
7474
.required(true),
@@ -87,13 +87,12 @@ private AmplitudeCreateAttributionEventAction() {
8787
}
8888

8989
public static String perform(Parameters inputParameters, Parameters connectionParameters, Context context) {
90-
9190
return context.http(http -> http.post("/attribution"))
9291
.configuration(responseType(ResponseType.TEXT))
9392
.queryParameters(
9493
API_KEY, connectionParameters.getRequiredString(API_KEY),
9594
EVENT, getEventJson(inputParameters, context))
9695
.execute()
97-
.getBody(new TypeReference<>() {});
96+
.getBody(String.class);
9897
}
9998
}

server/libs/modules/components/amplitude/src/main/java/com/bytechef/component/amplitude/action/AmplitudeCreateOrUpdateUserAction.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
import com.bytechef.component.definition.Context.Http.BodyContentType;
4646
import com.bytechef.component.definition.Context.Http.ResponseType;
4747
import com.bytechef.component.definition.Parameters;
48-
import com.bytechef.component.definition.TypeReference;
4948
import java.util.HashMap;
5049
import java.util.Map;
5150

@@ -72,8 +71,9 @@ public class AmplitudeCreateOrUpdateUserAction {
7271
.required(true),
7372
string(USER_ID)
7473
.label("User ID")
75-
.description("Unique user ID specified by you. If you send a request with a user ID that's not in " +
76-
"the Amplitude system, new user will be created (e.g. email address).")
74+
.description(
75+
"Unique user ID specified by you. If you send a request with a user ID that's not in the " +
76+
"Amplitude system, new user will be created (e.g. email address).")
7777
.displayCondition("%s == '%s'".formatted(ID, USER_ID))
7878
.required(true),
7979
USER_PROPERTIES_OBJECT,
@@ -139,7 +139,7 @@ public static String perform(Parameters inputParameters, Parameters connectionPa
139139
.header(CONTENT_TYPE, CONTENT_TYPE_URLENCODED)
140140
.body(Body.of(body, BodyContentType.FORM_URL_ENCODED))
141141
.execute()
142-
.getBody(new TypeReference<>() {});
142+
.getBody(String.class);
143143
}
144144

145145
private static void checkIfNull(Map<String, Object> body, String key, String value) {

server/libs/modules/components/amplitude/src/main/java/com/bytechef/component/amplitude/util/AmplitudeUtils.java

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.bytechef.component.definition.Context;
2929
import com.bytechef.component.definition.Option;
3030
import com.bytechef.component.definition.Parameters;
31+
import com.bytechef.component.definition.TypeReference;
3132
import java.util.ArrayList;
3233
import java.util.HashMap;
3334
import java.util.List;
@@ -67,8 +68,9 @@ public static List<Option<String>> getIdentifierKeyOptions(
6768

6869
List<Option<String>> options = new ArrayList<>();
6970

70-
if (inputParameters.getRequiredString(PLATFORM)
71-
.equals("ios")) {
71+
String platform = inputParameters.getRequiredString(PLATFORM);
72+
73+
if (platform.equals("ios")) {
7274
options.add(option("The Identifier for Advertiser", "idfa"));
7375
options.add(option("The Identifier for Vendor", "idfv"));
7476
} else {
@@ -82,15 +84,11 @@ public static List<Option<String>> getIdentifierKeyOptions(
8284
public static Map<String, String> getUserProperties(Parameters inputParameters) {
8385
Map<String, String> userProperties = new HashMap<>();
8486

85-
List<Map> userPropertiesList = inputParameters.getList(USER_PROPERTIES, Map.class);
87+
List<Map<String, String>> userPropertiesList = inputParameters.getList(
88+
USER_PROPERTIES, new TypeReference<>() {}, List.of());
8689

87-
if (userPropertiesList != null) {
88-
for (Map<?, ?> userProperty : userPropertiesList) {
89-
userProperties.put(userProperty.get(KEY)
90-
.toString(),
91-
userProperty.get(VALUE)
92-
.toString());
93-
}
90+
for (Map<String, String> userProperty : userPropertiesList) {
91+
userProperties.put(userProperty.get(KEY), userProperty.get(VALUE));
9492
}
9593

9694
return userProperties;

server/libs/modules/components/amplitude/src/test/java/com/bytechef/component/amplitude/action/AmplitudeCreateAttributionEventActionTest.java

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.bytechef.component.definition.Context.Http.Executor;
3636
import com.bytechef.component.definition.Context.Http.Response;
3737
import com.bytechef.component.definition.Parameters;
38-
import com.bytechef.component.definition.TypeReference;
3938
import com.bytechef.component.test.definition.MockParametersFactory;
4039
import java.util.List;
4140
import java.util.Map;
@@ -48,52 +47,49 @@
4847
*/
4948
class AmplitudeCreateAttributionEventActionTest {
5049

51-
private static final ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class);
52-
private static final String jsonString = "jsonString";
53-
private static final Context mockedContext = mock(Context.class);
54-
private static final Executor mockedExecutor = mock(Executor.class);
55-
private static final Parameters mockedParameters = MockParametersFactory.create(
50+
private final ArgumentCaptor<Context> contextArgumentCaptor = ArgumentCaptor.forClass(Context.class);
51+
private final Context mockedContext = mock(Context.class);
52+
private final Executor mockedExecutor = mock(Executor.class);
53+
private final Parameters mockedParameters = MockParametersFactory.create(
5654
Map.of(
5755
API_KEY, "api_key", EVENT_TYPE, "eventType", PLATFORM, "platform",
5856
IDENTIFIER, Map.of(KEY, "identifierKey", VALUE, "identifierValue"),
5957
USER_PROPERTIES, List.of(Map.of(KEY, "userPropertyKey", VALUE, "userPropertyValue"))));
60-
private static final Response mockedResponse = mock(Response.class);
61-
private static final ArgumentCaptor<Parameters> parametersArgumentCaptor =
62-
ArgumentCaptor.forClass(Parameters.class);
63-
private static final String responseString = "response";
64-
private static final ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
58+
private final Response mockedResponse = mock(Response.class);
59+
private final ArgumentCaptor<Parameters> parametersArgumentCaptor = ArgumentCaptor.forClass(Parameters.class);
60+
private final ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
6561

6662
@Test
6763
void testPerform() {
68-
when(mockedContext.http(any()))
69-
.thenReturn(mockedExecutor);
70-
when(mockedExecutor.configuration(responseType(any())))
71-
.thenReturn(mockedExecutor);
64+
String jsonString = "jsonString";
65+
String responseString = "response";
7266

7367
try (MockedStatic<AmplitudeUtils> amplitudeUtilsMockedStatic = mockStatic(AmplitudeUtils.class)) {
7468
amplitudeUtilsMockedStatic
7569
.when(() -> AmplitudeUtils.getEventJson(
7670
parametersArgumentCaptor.capture(), contextArgumentCaptor.capture()))
7771
.thenReturn(jsonString);
7872

73+
when(mockedContext.http(any()))
74+
.thenReturn(mockedExecutor);
75+
when(mockedExecutor.configuration(responseType(any())))
76+
.thenReturn(mockedExecutor);
7977
when(mockedExecutor.queryParameters(
8078
stringArgumentCaptor.capture(), stringArgumentCaptor.capture(),
8179
stringArgumentCaptor.capture(), stringArgumentCaptor.capture()))
8280
.thenReturn(mockedExecutor);
8381
when(mockedExecutor.execute())
8482
.thenReturn(mockedResponse);
85-
when(mockedResponse.getBody(any(TypeReference.class)))
83+
when(mockedResponse.getBody(String.class))
8684
.thenReturn(responseString);
8785

88-
String response =
89-
AmplitudeCreateAttributionEventAction.perform(mockedParameters, mockedParameters, mockedContext);
90-
assertEquals(responseString, response);
86+
String response = AmplitudeCreateAttributionEventAction.perform(
87+
mockedParameters, mockedParameters, mockedContext);
9188

89+
assertEquals(responseString, response);
9290
assertEquals(mockedParameters, parametersArgumentCaptor.getValue());
9391
assertEquals(mockedContext, contextArgumentCaptor.getValue());
94-
95-
List<String> expectedQueryParameters = List.of(API_KEY, "api_key", "event", jsonString);
96-
assertEquals(expectedQueryParameters, stringArgumentCaptor.getAllValues());
92+
assertEquals(List.of(API_KEY, "api_key", "event", jsonString), stringArgumentCaptor.getAllValues());
9793
}
9894
}
9995
}

server/libs/modules/components/amplitude/src/test/java/com/bytechef/component/amplitude/action/AmplitudeCreateOrUpdateUserActionTest.java

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
import com.bytechef.component.definition.Context.Http.Executor;
3939
import com.bytechef.component.definition.Context.Http.Response;
4040
import com.bytechef.component.definition.Parameters;
41-
import com.bytechef.component.definition.TypeReference;
4241
import com.bytechef.component.test.definition.MockParametersFactory;
4342
import java.util.List;
4443
import java.util.Map;
@@ -51,29 +50,22 @@
5150
*/
5251
class AmplitudeCreateOrUpdateUserActionTest {
5352

54-
private static final ArgumentCaptor<Body> bodyArgumentCaptor = ArgumentCaptor.forClass(Body.class);
55-
private static final String identificationJson = "identificationJson";
56-
private static final Context mockedContext = mock(Context.class);
57-
private static final Executor mockedExecutor = mock(Executor.class);
58-
private static final Map<String, Object> mockedIdentification = Map.of();
59-
private static final Parameters mockedParameters = MockParametersFactory.create(
53+
private final ArgumentCaptor<Body> bodyArgumentCaptor = ArgumentCaptor.forClass(Body.class);
54+
private final Context mockedContext = mock(Context.class);
55+
private final Executor mockedExecutor = mock(Executor.class);
56+
private final Map<String, Object> mockedIdentification = Map.of();
57+
private final Parameters mockedParameters = MockParametersFactory.create(
6058
Map.of(
6159
API_KEY, "api_key", ID, "id", USER_PROPERTIES,
6260
List.of(Map.of(KEY, "userPropertyKey", VALUE, "userPropertyValue"))));
63-
private static final Response mockedResponse = mock(Response.class);
64-
private static final ArgumentCaptor<Parameters> parametersArgumentCaptor =
65-
ArgumentCaptor.forClass(Parameters.class);
66-
private static final String responseString = "response";
67-
private static final ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
61+
private final Response mockedResponse = mock(Response.class);
62+
private final ArgumentCaptor<Parameters> parametersArgumentCaptor = ArgumentCaptor.forClass(Parameters.class);
63+
private final ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class);
6864

6965
@Test
7066
void testPerform() {
71-
when(mockedContext.http(any()))
72-
.thenReturn(mockedExecutor);
73-
when(mockedExecutor.configuration(responseType(any())))
74-
.thenReturn(mockedExecutor);
75-
when(mockedExecutor.header(stringArgumentCaptor.capture(), stringArgumentCaptor.capture()))
76-
.thenReturn(mockedExecutor);
67+
String identificationJson = "identificationJson";
68+
String responseString = "response";
7769

7870
try (MockedStatic<AmplitudeUtils> amplitudeUtilsMockedStatic = mockStatic(AmplitudeUtils.class)) {
7971
amplitudeUtilsMockedStatic
@@ -84,25 +76,29 @@ void testPerform() {
8476
when(mockedContext.json(any()))
8577
.thenReturn(identificationJson);
8678

79+
when(mockedContext.http(any()))
80+
.thenReturn(mockedExecutor);
81+
when(mockedExecutor.configuration(responseType(any())))
82+
.thenReturn(mockedExecutor);
83+
when(mockedExecutor.header(stringArgumentCaptor.capture(), stringArgumentCaptor.capture()))
84+
.thenReturn(mockedExecutor);
8785
when(mockedExecutor.body(bodyArgumentCaptor.capture()))
8886
.thenReturn(mockedExecutor);
8987
when(mockedExecutor.execute())
9088
.thenReturn(mockedResponse);
91-
when(mockedResponse.getBody(any(TypeReference.class)))
89+
when(mockedResponse.getBody(String.class))
9290
.thenReturn(responseString);
9391

94-
String response =
95-
AmplitudeCreateOrUpdateUserAction.perform(mockedParameters, mockedParameters, mockedContext);
96-
assertEquals(responseString, response);
92+
String response = AmplitudeCreateOrUpdateUserAction.perform(
93+
mockedParameters, mockedParameters, mockedContext);
9794

95+
assertEquals(responseString, response);
9896
assertEquals(mockedParameters, parametersArgumentCaptor.getValue());
99-
100-
List<String> expectedHeader = List.of(CONTENT_TYPE, CONTENT_TYPE_URLENCODED);
101-
assertEquals(expectedHeader, stringArgumentCaptor.getAllValues());
97+
assertEquals(List.of(CONTENT_TYPE, CONTENT_TYPE_URLENCODED), stringArgumentCaptor.getAllValues());
10298

10399
Body body = bodyArgumentCaptor.getValue();
104-
assertEquals(Map.of(API_KEY, "api_key", IDENTIFICATION, identificationJson), body.getContent());
105100

101+
assertEquals(Map.of(API_KEY, "api_key", IDENTIFICATION, identificationJson), body.getContent());
106102
assertEquals(BodyContentType.FORM_URL_ENCODED, body.getContentType());
107103
}
108104
}

0 commit comments

Comments
 (0)