cycles = new HashMap<>();
+ {
+ // TODO: complete other values
+ cycles.put(1440, "1 Day");
+ }
- Household sharedHousehold
- HouseholdUser sharedMasterUser
- HouseholdUser sharedUser
- String sharedMasterUserKs
- String sharedUserKs
+ /*================================================================================
+ Shared Test Params - end
================================================================================*/
+ @Parameters({"accountType"})
+ @BeforeSuite(alwaysRun = true)
+ public void baseTest_beforeSuite(@org.testng.annotations.Optional("opc") String accountType, ITestContext testContext) {
+ XmlSuite suite = testContext.getCurrentXmlTest().getSuite();
+ Logger.getLogger(BaseTest.class).debug("Start suite >>> Suite: " + suite.getName());
- @BeforeSuite
- public void base_test_before_suite() {
// set configuration
- config = new Configuration();
+ config = new Configuration();
config.setEndpoint(getProperty(API_BASE_URL) + "/" + getProperty(API_VERSION));
config.setAcceptGzipEncoding(false);
+ config.setReadTimeout(Integer.valueOf(getProperty(DEFAULT_TIMEOUT_IN_SEC))*1000);
// set client
client = new Client(config);
// set default awaitility timeout
- setDefaultTimeout(30, TimeUnit.SECONDS);
+ setDefaultTimeout(Long.parseLong(getProperty(DEFAULT_TIMEOUT_IN_SEC)), TimeUnit.SECONDS);
- // set shared common params
- partnerId = Integer.parseInt(getProperty(PARTNER_ID));
+ // set default users password
defaultUserPassword = getProperty(DEFAULT_USER_PASSWORD);
+
+ // set shared common params
+ if ("opc".equals(accountType)) {
+ isOpcGroup = true;
+ partnerId = Integer.parseInt(getProperty(OPC_PARTNER_ID));
+ } else {
+ isOpcGroup = false;
+ partnerId = Integer.parseInt(getProperty(PARTNER_ID));
+ }
+
+ // set performance report
+ if ("true".equals(getProperty(WRITE_REGRESSION_LOGS)) && numOfSuites == getNumOfSuites()) {
+ File logsDir = new File(getProperty(LOGS_DIR));
+ if (Files.exists(logsDir.toPath())) {
+ try {
+ FileUtils.cleanDirectory(new File(getProperty(LOGS_DIR)));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ // decrement numOfSuites in order to generate the performance report after all suites finish
+ numOfSuites--;
+ }
+
+ @BeforeMethod(alwaysRun = true)
+ public void baseTest_beforeMethod(Method method) {
+ Logger.getLogger(BaseTest.class).debug("Start test >>> Class: " + getClass().getSimpleName() + ", Test: " + method.getName());
+ }
+
+ @AfterMethod(alwaysRun = true)
+ public void baseTest_afterMethod(Method method) {
+ Logger.getLogger(BaseTest.class).debug("End test >>> Class: " + getClass().getSimpleName() + ", Test: " + method.getName());
+ }
+
+ /**
+ * Regression requires existing of Price Plan with specific parameters.
+ * Price should be 5 Euros
+ * Discount percent should be equal 100%
+ *
+ * In case item is not found in DB it will be ingested.
+ * Can't work in case proper Discount and PriceCode aren't found in DB
+ *
+ * @return common shared Price Plan with mentioned parameters
+ */
+ public static PricePlan getSharedCommonPricePlan() {
+ if (sharedCommonPricePlan == null) {
+ sharedCommonPricePlan = IngestFixtureData.loadPricePlan(Double.valueOf(COMMON_PRICE_CODE_AMOUNT), EUR.getValue(), getSharedCommonDiscount());
+ if (sharedCommonPricePlan == null) {
+ PpData ppData = new PpData()
+ .fullLifeCycle(cycles.get(CYCLE_1_DAY))
+ .viewLifeCycle(cycles.get(CYCLE_1_DAY))
+ .maxViews(0)
+ .price(COMMON_PRICE_CODE_AMOUNT)
+ .currency(EUR.getValue())
+ .discount(IngestFixtureData.getDiscountByPercentAndCurrency(EUR.getValue(), getSharedCommonDiscount().getPercent().intValue()))
+ .isRenewable(true)
+ .recurringPeriods(0);
+
+ sharedCommonPricePlan = insertPp(ppData);
+ }
+ }
+ return sharedCommonPricePlan;
+ }
+
+ /**
+ * Regression requires existing of Price Plan with specific parameters.
+ * One of them:
+ * Discount percent should be equal 100%
+ * Can't work in case proper Discount and PriceCode aren't found in DB
+ *
+ * @return common shared Discount Module with mentioned parameters
+ */
+ public static DiscountModule getSharedCommonDiscount() {
+ double defaultDiscountPrice = 0.0;
+ double defaultDiscountPercentValue = 100.0;
+ if (sharedCommonDiscountModule == null) {
+ sharedCommonDiscountModule = IngestFixtureData.loadDiscount(defaultDiscountPrice, defaultDiscountPercentValue);
+ }
+ return sharedCommonDiscountModule;
+ }
+
+ /**
+ * Regression requires existing of MPP with specific parameters.
+ * Price Plan should be as for method public static PricePlan getSharedCommonPricePlan()
+ *
+ * MPP shouldn't be renewed and with discount (internal items) 100%
+ *
+ * @return MPP with mentioned parameters
+ */
+ public static Subscription getSharedCommonSubscription() {
+ double defaultDiscountPercentValue = 100.0;
+ if (sharedCommonSubscription == null) {
+ sharedCommonSubscription = IngestFixtureData.loadSharedCommonSubscription(getSharedCommonPricePlan());
+ if (sharedCommonSubscription == null) {
+ MppData mppData = new MppData()
+ .pricePlanCode1(getSharedCommonPricePlan().getName())
+ .internalDiscount(IngestFixtureData.getDiscountByPercentAndCurrency(EUR.getValue(), (int) defaultDiscountPercentValue));
+ sharedCommonSubscription = insertMpp(mppData);
+ }
+
+ // it should have at least 1 VOD
+ if (getAssetsListBySubscription(Integer.valueOf(sharedCommonSubscription.getId()), Optional.empty(), true) == null ||
+ getAssetsListBySubscription(Integer.valueOf(sharedCommonSubscription.getId()), Optional.empty(), true).size() == 0) {
+ ingestVODIntoSubscription(sharedCommonSubscription);
+ }
+ }
+ return sharedCommonSubscription;
+ }
+
+ /**
+ * Regression requires existence of Collection with specific parameters.
+ * Price should be as for method public static PricePlan getSharedCommonPricePlan()
+ * Usage Module should be as for method public static PricePlan getSharedCommonPricePlan()
+ *
+ * Collection should be with discount (internal items) 100%
+ *
+ * @return Collection with mentioned parameters
+ */
+ public static Collection getSharedCommonCollection() {
+ if (sharedCommonCollection == null) {
+ sharedCommonCollection = IngestFixtureData.loadSharedCommonCollection(getSharedCommonPricePlan());
+ if (sharedCommonCollection == null) {
+ Logger.getLogger(BaseTest.class).error("Collection with defined parameters should exist in DB!");
+ }
+ }
+ return sharedCommonCollection;
+ }
+
+ /**
+ * Regression requires existing of PPV with specific parameters.
+ * Price Plan should be as for method public static PricePlan getSharedCommonPricePlan()
+ *
+ * PPV should be with discount (internal items) 50%
+ *
+ * @return PPV with mentioned parameters
+ */
+ public static Ppv getSharedCommonPpv(){
+ double discountPercentValue = 50.0;
+ if (sharedCommonPpv == null) {
+ sharedCommonPpv = IngestFixtureData.loadSharedCommonPpv(getSharedCommonPricePlan());
+ if (sharedCommonPpv == null) {
+ PpvData ppvData = new PpvData()
+ .discountCode(IngestFixtureData.getDiscountByPercentAndCurrency(EUR.getValue(), (int) discountPercentValue))
+ .usageModule(getSharedCommonPricePlan().getName());
+ sharedCommonPpv = insertPpv(ppvData);
+ }
+ }
+ return sharedCommonPpv;
+ }
+
+ public static String getIngestBusinessModuleUserName() {
+ if (ingestBusinessModuleUserUsername == null) {
+ String userInfo = IngestFixtureData.getIngestItemUserData(partnerId);
+ ingestBusinessModuleUserUsername = userInfo.split(":")[0];
+ ingestBusinessModuleUserPassword = userInfo.split(":")[1];
+ }
+ return ingestBusinessModuleUserUsername;
+ }
+
+ public static String getIngestBusinessModuleUserPassword() {
+ if (ingestBusinessModuleUserPassword == null) {
+ String userInfo = IngestFixtureData.getIngestItemUserData(partnerId);
+ ingestBusinessModuleUserUsername = userInfo.split(":")[0];
+ ingestBusinessModuleUserPassword = userInfo.split(":")[1];
+ }
+ return ingestBusinessModuleUserPassword;
+ }
+
+ public static String getIngestAssetUserName() {
+ if (ingestAssetUserUsername == null) {
+ String userInfo = isOpcGroup
+ ? IngestFixtureData.getIngestItemUserData(partnerId)
+ : IngestFixtureData.getIngestItemUserData(partnerId + 1);
+ ingestAssetUserUsername = userInfo.split(":")[0];
+ ingestAssetUserPassword = userInfo.split(":")[1];
+ }
+ return ingestAssetUserUsername;
+ }
+
+ public static String getIngestAssetUserPassword() {
+ if (ingestAssetUserPassword == null) {
+ String userInfo = isOpcGroup
+ ? IngestFixtureData.getIngestItemUserData(partnerId)
+ : IngestFixtureData.getIngestItemUserData(partnerId + 1);
+ ingestAssetUserUsername = userInfo.split(":")[0];
+ ingestAssetUserPassword = userInfo.split(":")[1];
+ }
+ return ingestAssetUserPassword;
+ }
+
+ public static String getIngestVirtualAssetUserName() {
+ if (ingestVirtualAssetUserUsername == null) {
+ String userInfo = isOpcGroup
+ ? IngestFixtureData.getIngestItemUserData(partnerId)
+ : IngestFixtureData.getIngestItemUserData(partnerId + 2);
+ ingestVirtualAssetUserUsername = userInfo.split(":")[0];
+ ingestVirtualAssetUserPassword = userInfo.split(":")[1];
+ }
+ return ingestVirtualAssetUserUsername;
+ }
+
+ public static String getIngestVirualAssetUserPassword() {
+ if (ingestVirtualAssetUserPassword == null) {
+ String userInfo = isOpcGroup
+ ? IngestFixtureData.getIngestItemUserData(partnerId)
+ : IngestFixtureData.getIngestItemUserData(partnerId + 2);
+ ingestVirtualAssetUserUsername = userInfo.split(":")[0];
+ ingestVirtualAssetUserPassword = userInfo.split(":")[1];
+ }
+ return ingestVirtualAssetUserPassword;
}
// getters for shared params
public static String getAdministratorKs() {
if (administratorKs == null) {
- String[] userInfo = DBUtils.getUserDataByRole("Administrator").split(":");
- loginResponse = executor.executeSync(login(partnerId, userInfo[0], userInfo[1],
- null,null));
+ String[] userInfo = DBUtils.getUserData("Administrator").split(":");
+ loginResponse = executor.executeSync(login(partnerId, userInfo[0], userInfo[1]));
administratorKs = loginResponse.results.getLoginSession().getKs();
}
return administratorKs;
@@ -106,9 +369,8 @@ public static String getAdministratorKs() {
public static String getOperatorKs() {
if (operatorKs == null) {
- String[] userInfo = DBUtils.getUserDataByRole("Operator").split(":");
- loginResponse = executor.executeSync(login(partnerId, userInfo[0], userInfo[1],
- null,null));
+ String[] userInfo = DBUtils.getUserData("Operator").split(":");
+ loginResponse = executor.executeSync(login(partnerId, userInfo[0], userInfo[1]));
operatorKs = loginResponse.results.getLoginSession().getKs();
}
return operatorKs;
@@ -116,9 +378,8 @@ public static String getOperatorKs() {
public static String getManagerKs() {
if (managerKs == null) {
- String[] userInfo = DBUtils.getUserDataByRole("Manager").split(":");
- loginResponse = executor.executeSync(login(partnerId, userInfo[0], userInfo[1],
- null,null));
+ String[] userInfo = DBUtils.getUserData("Manager").split(":");
+ loginResponse = executor.executeSync(login(partnerId, userInfo[0], userInfo[1]));
managerKs = loginResponse.results.getLoginSession().getKs();
}
return managerKs;
@@ -126,7 +387,7 @@ public static String getManagerKs() {
public static String getAnonymousKs() {
if (anonymousKs == null) {
- Response loginSession = executor.executeSync(OttUserService.anonymousLogin(partnerId));
+ Response loginSession = executor.executeSync(anonymousLogin(partnerId));
anonymousKs = loginSession.results.getKs();
}
return anonymousKs;
@@ -134,54 +395,159 @@ public static String getAnonymousKs() {
public static MediaAsset getSharedMediaAsset() {
if (mediaAsset == null) {
- mediaAsset = IngestUtils.ingestVOD(Optional.empty(), Optional.empty(), true, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
- Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
+ VodData vodData = new VodData();
+ mediaAsset = insertVod(vodData, true);
}
return mediaAsset;
}
+ public static String getSharedEpgChannelName() {
+ if (epgChannelName == null) {
+ epgChannelName = DBUtils.getLinearAssetIdAndEpgChannelNameJsonArray().getJSONObject(0).getString("name");
+ }
+ return epgChannelName;
+ }
+
+ public static ProgramAsset getSharedEpgProgram() {
+ if (epgProgram == null) {
+ epgProgram = insertEpg(new EpgData(getSharedEpgChannelName())).get(0);
+ }
+ return (ProgramAsset) epgProgram;
+ }
+
+
public static MediaFile getSharedWebMediaFile() {
if (webMediaFile == null) {
- if (getProperty(WEB_FILE_TYPE).equals(getSharedMediaAsset().getMediaFiles().get(0).getType())) {
- webMediaFile = mediaAsset.getMediaFiles().get(0);
- } else {
- webMediaFile = mediaAsset.getMediaFiles().get(1);
- }
+ webMediaFile = getMediaFileByType(getSharedMediaAsset(), getProperty(WEB_FILE_TYPE));
}
return webMediaFile;
}
public static MediaFile getSharedMobileMediaFile() {
if (mobileMediaFile == null) {
- if (getProperty(MOBILE_FILE_TYPE).equals(getSharedMediaAsset().getMediaFiles().get(0).getType())) {
- mobileMediaFile = mediaAsset.getMediaFiles().get(0);
- } else {
- mobileMediaFile = mediaAsset.getMediaFiles().get(1);
- }
+ mobileMediaFile = getMediaFileByType(getSharedMediaAsset(), getProperty(MOBILE_FILE_TYPE));
}
return mobileMediaFile;
}
+ public static MediaFile getMediaFileByType(MediaAsset asset, String fileType) {
+ MediaFile mediaFile;
+ if (fileType.equals(asset.getMediaFiles().get(0).getType())) {
+ mediaFile = mediaAsset.getMediaFiles().get(0);
+ } else {
+ mediaFile = mediaAsset.getMediaFiles().get(1);
+ }
+ return mediaFile;
+ }
+
public static Subscription get5MinRenewableSubscription() {
if (fiveMinRenewableSubscription == null) {
- PricePlan pricePlan = IngestUtils.ingestPP(Optional.empty(), Optional.empty(), Optional.empty(),
- Optional.of(FIVE_MINUTES_PERIOD), Optional.of(FIVE_MINUTES_PERIOD), Optional.empty(),
- Optional.of(getProperty(PRICE_CODE_AMOUNT)), Optional.of(CURRENCY_EUR), Optional.of(""),
- Optional.of(true), Optional.of(3));
- fiveMinRenewableSubscription = IngestUtils.ingestMPP(Optional.empty(), Optional.empty(), Optional.empty(),
- Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
- Optional.of(true), Optional.empty(), Optional.of(pricePlan.getName()), Optional.empty(), Optional.empty(), Optional.empty(),
- Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
+ fiveMinRenewableSubscription = IngestFixtureData.loadShared5MinutesRenewableSubscription();
+ // it should have at least 1 VOD
+ if (getAssetsListBySubscription(Integer.valueOf(fiveMinRenewableSubscription.getId()), Optional.empty(), true) == null ||
+ getAssetsListBySubscription(Integer.valueOf(fiveMinRenewableSubscription.getId()), Optional.empty(), true).size() == 0) {
+ ingestVODIntoSubscription(fiveMinRenewableSubscription);
+ }
+
+ if (fiveMinRenewableSubscription == null) {
+ PpData ppData = new PpData()
+ .fullLifeCycle(FIVE_MINUTES_PERIOD)
+ .viewLifeCycle(FIVE_MINUTES_PERIOD)
+ .price(PRICE_CODE_AMOUNT)
+ .currency(EUR.getValue())
+ .isRenewable(true)
+ .recurringPeriods(3);
+
+ PricePlan pricePlan = insertPp(ppData);
+
+ // it should have at least 1 VOD
+ DynamicChannel channel = loadDefaultChannel();
+ channel.setKSql("name='" + getSharedMediaAsset().getName() + "'");
+ AddChannelBuilder addChannelBuilder = add(channel);
+ Response channelResponse = executor.executeSync(addChannelBuilder.setKs(getManagerKs()));
+ if (channelResponse.results != null && channelResponse.results.getName() != null) {
+ MppData mppData = new MppData()
+ .pricePlanCode1(pricePlan.getName())
+ .channel2(channelResponse.results.getName());
+ fiveMinRenewableSubscription = insertMpp(mppData);
+ }
+ }
}
return fiveMinRenewableSubscription;
}
+ private static void ingestVODIntoSubscription(Subscription subscription) {
+ // getting channel
+ SubscriptionFilter filter = new SubscriptionFilter();
+ filter.setSubscriptionIdIn(subscription.getId());
+ Response> listResponse = executor.executeSync(list(filter)
+ .setKs(getOperatorKs()));
+
+ verify(listResponse.results.getObjects().get(0).getChannels().size() > 0);
+ int channelId = listResponse.results.getObjects().get(0).getChannels().get(0).getId().intValue();
+
+ // get channel
+ DynamicChannel channel = (DynamicChannel) executor.executeSync(get(channelId)
+ .setKs(getOperatorKs()))
+ .results;
+
+ String[] parameters;
+ String tag = null;
+ String name = null;
+
+ if (channel.getKSql() == null || channel.getKSql().equals("")) {
+ // automatic channel
+ String automaticChannelExpression = IngestFixtureData.getAutomaticChannelExpression(channelId);
+ parameters = automaticChannelExpression.split(":");
+ verify(parameters.length == 2);
+ tag = parameters[0];
+ } else {
+ // KSQL channel
+ parameters = channel.getKSql().split("=");
+ verify(parameters.length == 2);
+ if ("name".equals(parameters[0].toLowerCase())) {
+ // ingest VOD with mentioned name
+ name = parameters[0];
+ } else {
+ // ingest VOD with Tag/Meta (currently supports only tags!!!)
+ tag = parameters[0];
+ }
+ }
+ if (name != null) {
+ // ingest VOD by name
+ VodData vodData = new VodData();
+ MediaAsset mediaAsset = insertVod(vodData, true);
+
+ vodData.name(name);
+ updateVod(mediaAsset.getName(), vodData);
+ }
+ if (tag != null) {
+ // ingest VOD by tag
+ Map> tags = new HashMap<>();
+ List values = new ArrayList<>();
+ values.add(parameters[1].replaceAll("'", ""));
+ tags.put(tag, values);
+
+ VodData vodData = new VodData().tags(tags);
+ insertVod(vodData, true);
+ }
+ }
+
+ private static DynamicChannel loadDefaultChannel() {
+ DynamicChannel channel = new DynamicChannel();
+ channel.setMultilingualName(setTranslationToken(getRandomValue("Channel_")));
+ channel.setMultilingualDescription(setTranslationToken("Description of " + channel.getName()));
+ channel.setIsActive(true);
+ channel.setAssetTypes(null);
+ return channel;
+ }
+
// shared household
public static class SharedHousehold {
- private static Household sharedHousehold;
- private static HouseholdUser sharedMasterUser, sharedUser;
- private static String sharedMasterUserKs, sharedUserKs;
+ @Shared private static Household sharedHousehold;
+ @Shared private static HouseholdUser sharedMasterUser, sharedUser;
+ @Shared private static String sharedMasterUserKs, sharedUserKs;
public static Household getSharedHousehold() {
@@ -190,23 +556,24 @@ public static Household getSharedHousehold() {
if (sharedHousehold == null) {
sharedHousehold = createHousehold(numOfUsers, numOfDevices, true);
- List sharedHouseholdUsers = getUsersListFromHouseHold(sharedHousehold);
+ List sharedHouseholdUsers = getUsersList(sharedHousehold);
for (HouseholdUser user : sharedHouseholdUsers) {
if (user.getIsMaster() != null && user.getIsMaster()) {
sharedMasterUser = user;
}
- // TODO: ask Alon if we have cases when commented part should be there? What tests related to that logic?
- if (user.getIsMaster() == null/* && user.getIsDefault() == null*/) {
+ if (user.getIsMaster() == null && user.getIsDefault() == null) {
sharedUser = user;
}
}
- String sharedMasterUserName = getUserById(Integer.parseInt(sharedMasterUser.getUserId())).getUsername();
- loginResponse = executor.executeSync(login(partnerId, sharedMasterUserName, defaultUserPassword,null,null));
+ List sharedHouseholdDevices = getDevicesList(sharedHousehold);
+ String sharedMasterUserName = getOttUserById(Integer.parseInt(sharedMasterUser.getUserId())).getUsername();
+ loginResponse = executor.executeSync(login(partnerId, sharedMasterUserName, defaultUserPassword,null,sharedHouseholdDevices.get(0).getUdid()));
sharedMasterUserKs = loginResponse.results.getLoginSession().getKs();
- String sharedUserName = getUserById(Integer.parseInt(sharedUser.getUserId())).getUsername();
- loginResponse = executor.executeSync(login(partnerId, sharedUserName, defaultUserPassword,null,null));
+ String sharedUserName = getOttUserById(Integer.parseInt(sharedUser.getUserId())).getUsername();
+ loginResponse = executor.executeSync(login(partnerId, sharedUserName, defaultUserPassword,null,sharedHouseholdDevices.get(1).getUdid()));
+
sharedUserKs = loginResponse.results.getLoginSession().getKs();
}
return sharedHousehold;
@@ -232,4 +599,50 @@ public static HouseholdUser getSharedUser() {
return sharedUser;
}
}
+
+ @AfterSuite(alwaysRun = true)
+ public void baseTest_afterSuite(ITestContext testContext) {
+ XmlSuite suite = testContext.getCurrentXmlTest().getSuite();
+ Logger.getLogger(BaseTest.class).debug("End suite >>> Suite: " + suite.getName());
+
+ // reset shared params
+ resetSharedParams();
+
+ // generate performance report
+ if ("true".equals(getProperty(WRITE_REGRESSION_LOGS)) && numOfSuites == 0) {
+ PerformanceUtils.generatePerformanceReport();
+ }
+
+ // TODO: 8/14/2018 cleanup: delete generated shared resources and data!
+ }
+
+ private static int getNumOfSuites() {
+ Document doc = getDocument("src/test/resources/testng.xml");
+ NodeList suites = doc.getElementsByTagName("suite-file");
+ return suites.getLength();
+ }
+
+ void resetSharedParams() {
+ Logger.getLogger(BaseTest.class).debug("start resetSharedParams()");
+
+ // TODO: 9/5/2018 make dynamic in case more inner classes will be added
+ Field[] baseTestFields = BaseTest.class.getDeclaredFields();
+ Field[] sharedHouseholdFields = SharedHousehold.class.getDeclaredFields();
+ Field[] fields = ArrayUtils.addAll(baseTestFields, sharedHouseholdFields);
+
+ for (Field field : fields) {
+ for (Annotation annotation : field.getDeclaredAnnotations()) {
+ if (annotation instanceof Shared) {
+ try {
+ field.setAccessible(true);
+ field.set(this, null);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ Logger.getLogger(BaseTest.class).debug("finish resetSharedParams()");
+ }
}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/AssetStructMetaType.java b/src/test/java/com/kaltura/client/test/tests/enums/AssetStructMetaType.java
new file mode 100644
index 000000000..3a5366c01
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/AssetStructMetaType.java
@@ -0,0 +1,83 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+public enum AssetStructMetaType implements EnumAsString {
+ MULTI_LINGUAL_TEXT("Text"),
+ STRING("String"),
+ NUMBER("Number"),
+ DATE("Date"),
+ BOOLEAN("Boolean"),
+ //TAG("tag"),
+ ALL("All");
+
+ private String value;
+ private static List idsOfMetaTypes = null;
+// private static Map types2IdsInDb = null;
+
+ /*Data chosen from that ENUM provided by Lior
+ public enum MetaType
+ {
+ All = 0,
+ String = 1,
+ Number = 2,
+ Bool = 3,
+ Tag = 4,
+ DateTime = 5,
+ MultilingualString = 6
+ }*/
+ public static List getIdsOfMetaTypes() {
+ if (idsOfMetaTypes == null) {
+ idsOfMetaTypes = new ArrayList<>();
+ idsOfMetaTypes.add(6); // text multilingual
+ idsOfMetaTypes.add(2); // number
+ idsOfMetaTypes.add(5); // date
+ idsOfMetaTypes.add(3); // boolean
+ idsOfMetaTypes.add(1); // String
+ }
+ return idsOfMetaTypes;
+ }
+
+// public static Map getTypes2IdsInDb() {
+// if (types2IdsInDb == null) {
+// types2IdsInDb.put("Text", 6);
+// types2IdsInDb.put("Number", 2);
+// types2IdsInDb.put("Date", 5);
+// types2IdsInDb.put("Boolean", 3);
+// types2IdsInDb.put("String", 1);
+// }
+// return types2IdsInDb;
+// }
+
+ AssetStructMetaType(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static AssetStructMetaType get(String value) {
+ if(value == null) {
+ return null;
+ }
+
+ // goes over defined values and compare the inner value with the given one:
+ for(AssetStructMetaType item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return AssetStructMetaType.values().length > 0 ? AssetStructMetaType.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/ChannelType.java b/src/test/java/com/kaltura/client/test/tests/enums/ChannelType.java
new file mode 100644
index 000000000..96de7d6c2
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/ChannelType.java
@@ -0,0 +1,40 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+public enum ChannelType implements EnumAsString {
+ AUTOMATIC_CHANNEL_TYPE("1"),
+ KSQL_CHANNEL_TYPE("4"),
+ MANUAL_CHANNEL_TYPE("2");
+
+ private String value;
+
+ ChannelType(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static ChannelType get(String value) {
+ if(value == null)
+ {
+ return null;
+ }
+
+ // goes over Channel types defined values and compare the inner value with the given one:
+ for(ChannelType item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return ChannelType.values().length > 0 ? ChannelType.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/Currency.java b/src/test/java/com/kaltura/client/test/tests/enums/Currency.java
new file mode 100644
index 000000000..8b23a2570
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/Currency.java
@@ -0,0 +1,40 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+public enum Currency implements EnumAsString {
+ EUR("EUR"),
+ ILS("ILS"),
+ CLP("CLP"),
+ USD("USD");
+
+ private String value;
+
+ Currency(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static Currency get(String value) {
+ if(value == null) {
+ return null;
+ }
+
+ // goes over Currency defined values and compare the inner value with the given one:
+ for(Currency item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return Currency.values().length > 0 ? Currency.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/DurationPeriod.java b/src/test/java/com/kaltura/client/test/tests/enums/DurationPeriod.java
new file mode 100644
index 000000000..c3a54b497
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/DurationPeriod.java
@@ -0,0 +1,40 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+public enum DurationPeriod implements EnumAsString {
+ DAYS("days"),
+ HOURS("hours"),
+ MINUTES("minutes"),
+ SECONDS("seconds");
+
+ private String value;
+
+ DurationPeriod(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static DurationPeriod get(String value) {
+ if(value == null) {
+ return null;
+ }
+
+ // goes over Currency defined values and compare the inner value with the given one:
+ for(DurationPeriod item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return Currency.values().length > 0 ? DurationPeriod.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/IngestAction.java b/src/test/java/com/kaltura/client/test/tests/enums/IngestAction.java
new file mode 100644
index 000000000..d55dc819c
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/IngestAction.java
@@ -0,0 +1,39 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+public enum IngestAction implements EnumAsString {
+ INSERT("insert"),
+ UPDATE("update"),
+ DELETE("delete");
+
+ private String value;
+
+ IngestAction(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static IngestAction get(String value) {
+ if(value == null) {
+ return null;
+ }
+
+ // goes over IngestAction defined values and compare the inner value with the given one:
+ for(IngestAction item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return IngestAction.values().length > 0 ? IngestAction.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/KsqlKey.java b/src/test/java/com/kaltura/client/test/tests/enums/KsqlKey.java
new file mode 100644
index 000000000..36201220e
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/KsqlKey.java
@@ -0,0 +1,48 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+public enum KsqlKey implements EnumAsString {
+
+ NAME("name"),
+ START_DATE("start_date"),
+ END_DATE("end_date"),
+ GEO_BLOCK("geo_block"),
+ PARENTAL_RULES("parental_rules"),
+ USER_INTERESTS("user_interests"),
+ EPG_CHANNEL_ID("epg_channel_id"),
+ EPG_ID("epg_id"),
+ MEDIA_ID("media_id"),
+ ENTITLED_ASSETS("entitled_assets"),
+ ASSET_TYPE("asset_type");
+
+ private String value;
+
+ KsqlKey(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static KsqlKey get(String value) {
+ if(value == null) {
+ return null;
+ }
+
+ // goes over Currency defined values and compare the inner value with the given one:
+ for(KsqlKey item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return Currency.values().length > 0 ? KsqlKey.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/MediaType.java b/src/test/java/com/kaltura/client/test/tests/enums/MediaType.java
new file mode 100644
index 000000000..0e78e531d
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/MediaType.java
@@ -0,0 +1,41 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+public enum MediaType implements EnumAsString {
+ MOVIE("Movie"),
+ SERIES("Series"),
+ EPISODE("Episode"),
+ LINEAR("Linear"),
+ PACKAGE("Package");
+
+ private String value;
+
+ MediaType(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static MediaType get(String value) {
+ if(value == null) {
+ return null;
+ }
+
+ // goes over Currency defined values and compare the inner value with the given one:
+ for(MediaType item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return Currency.values().length > 0 ? MediaType.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/enums/PremiumService.java b/src/test/java/com/kaltura/client/test/tests/enums/PremiumService.java
new file mode 100644
index 000000000..8ca00d71d
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/enums/PremiumService.java
@@ -0,0 +1,41 @@
+package com.kaltura.client.test.tests.enums;
+
+import com.kaltura.client.enums.EnumAsString;
+
+public enum PremiumService implements EnumAsString {
+ CATCH_UP("1"),
+ START_OVER("2"),
+ NPVR("3"),
+ DOWNLOAD("4"),
+ AD_CONTROL("5");
+
+ private String value;
+
+ PremiumService(String value) {
+ this.value = value;
+ }
+
+ @Override
+ public String getValue() {
+ return this.value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public static PremiumService get(String value) {
+ if(value == null) {
+ return null;
+ }
+
+ // goes over Currency defined values and compare the inner value with the given one:
+ for(PremiumService item: values()) {
+ if(item.getValue().equals(value)) {
+ return item;
+ }
+ }
+ // in case the requested value was not found in the enum values, we return the first item as default.
+ return Currency.values().length > 0 ? PremiumService.values()[0]: null;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/featuresTests/productPriceTests/ListTests.java b/src/test/java/com/kaltura/client/test/tests/featuresTests/productPriceTests/ListTests.java
deleted file mode 100644
index 4211b5d5b..000000000
--- a/src/test/java/com/kaltura/client/test/tests/featuresTests/productPriceTests/ListTests.java
+++ /dev/null
@@ -1,22 +0,0 @@
-package com.kaltura.client.test.tests.featuresTests.productPriceTests;
-
-import com.kaltura.client.Client;
-import com.kaltura.client.test.tests.BaseTest;
-import org.testng.annotations.BeforeClass;
-
-public class ListTests extends BaseTest {
-
- private Client client;
-
- @BeforeClass
- public void beforeClass() {
-
- /*Ppv ppv = IngestUtils.ingestPPV(INGEST_ACTION_INSERT, true, "My ingest PPV", getProperty(FIFTY_PERCENTS_ILS_DISCOUNT_NAME),
- Double.valueOf(getProperty(PRICE_CODE_AMOUNT_4_99)), CURRENCY_EUR, getProperty(DEFAULT_USAGE_MODULE_4_INGEST_PPV), false, false,
- getProperty(DEFAULT_PRODUCT_CODE), getProperty(WEB_FILE_TYPE), getProperty(MOBILE_FILE_TYPE));*/
-
- /*Response> ingestedProgrammes = IngestUtils.ingestEPG("Shmulik_Series_1", Optional.of(2), Optional.empty(), Optional.of(30),
- Optional.of("minutes"), Optional.empty(), Optional.of(1), Optional.empty(), Optional.empty(), Optional.empty());
- System.out.println("ID:" + ingestedProgrammes.results.getObjects().get(0).getId());*/
- }
-}
diff --git a/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/five_zero_three/ParentChildMetadataInheritanceTests.java b/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/five_zero_three/ParentChildMetadataInheritanceTests.java
new file mode 100644
index 000000000..84806399a
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/five_zero_three/ParentChildMetadataInheritanceTests.java
@@ -0,0 +1,671 @@
+package com.kaltura.client.test.tests.featuresTests.versions.five_zero_three;
+
+import com.kaltura.client.enums.AssetReferenceType;
+import com.kaltura.client.services.*;
+import com.kaltura.client.services.AssetStructService.*;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.MediaType;
+import com.kaltura.client.test.utils.dbUtils.DBUtils;
+import com.kaltura.client.test.utils.ingestUtils.IngestVodUtils;
+import com.kaltura.client.types.*;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Link;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static com.kaltura.client.test.tests.enums.AssetStructMetaType.ALL;
+import static com.kaltura.client.test.tests.enums.IngestAction.INSERT;
+import static com.kaltura.client.test.utils.AssetStructMetaUtils.loadAssetStructMeta;
+import static com.kaltura.client.test.utils.AssetStructUtils.copyAssetStructObject;
+import static com.kaltura.client.test.utils.AssetStructUtils.getAssetStruct;
+import static com.kaltura.client.test.utils.AssetStructUtils.setInheritanceFieldsInAssetStruct;
+import static com.kaltura.client.test.utils.AssetUtils.getMediaAsset;
+import static com.kaltura.client.test.utils.BaseUtils.getCurrentDateInFormat;
+import static com.kaltura.client.test.utils.ingestUtils.BaseIngestUtils.DEFAULT_LANGUAGE;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodOpcUtils.getVodData;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.deleteVod;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.insertVod;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.updateVod;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ *
+ * Class to test functionality described in https://kaltura.atlassian.net/browse/BEO-5423
+ */
+@Link(name = "Parent Child Metadata Inheritance", url = "BEO-5423")
+@Test(groups = { "opc", "Parent Child Metadata Inheritance" })
+public class ParentChildMetadataInheritanceTests extends BaseTest {
+
+ private String metaIds;
+ private String allMetaIds;
+ private Response> sharedAssetStructListResponse;
+ private AssetStruct sharedAssetStruct1, sharedAssetStruct2;
+ private AssetStructMeta sharedMetaString1, sharedMetaString2, sharedMetaNumber1, sharedMetaNumber2;
+ private AssetStructMeta sharedMetaDate1, sharedMetaDate2, sharedMetaBoolean1, sharedMetaBoolean2;
+ private String sharedBasicMetaIds;
+ private String language1;
+ private Map> partMetas = new HashMap<>();
+ private Map> allMetas = new HashMap<>();
+ private Map> allUpdatedMetas = new HashMap<>();
+
+ @BeforeClass()
+ public void setUp() {
+ List languages = executor.executeSync(LanguageService.list(new LanguageFilter())
+ .setKs(getOperatorKs())).results.getObjects();
+ language1 = languages.get(0).getCode();
+ // TODO: check if assetStructList be useful at the end
+ // assetStructList to fill default metaIds
+// AssetStructFilter filter = new AssetStructFilter();
+// ListAssetStructBuilder listAssetStructBuilder = AssetStructService.list(filter);
+// sharedAssetStructListResponse = executor.executeSync(listAssetStructBuilder
+// .setKs(getOperatorKs()));
+// assertThat(sharedAssetStructListResponse.results.getTotalCount()).isGreaterThan(0);
+// metaIds = sharedAssetStructListResponse.results.getObjects().get(0).getMetaIds();
+
+ // identify shared assetStructMetas
+ List assetStructNames = DBUtils.getAssetStructMetas(ALL, 2);
+ sharedMetaString1 = loadAssetStructMeta(assetStructNames.get(0));
+ sharedMetaString2 = loadAssetStructMeta(assetStructNames.get(1));
+ sharedMetaNumber1 = loadAssetStructMeta(assetStructNames.get(2));
+ sharedMetaNumber2 = loadAssetStructMeta(assetStructNames.get(3));
+ sharedMetaDate1 = loadAssetStructMeta(assetStructNames.get(4));
+ sharedMetaDate2 = loadAssetStructMeta(assetStructNames.get(5));
+ sharedMetaBoolean1 = loadAssetStructMeta(assetStructNames.get(6));
+ sharedMetaBoolean2 = loadAssetStructMeta(assetStructNames.get(7));
+ // TODO: ask Lior why ONLY these ids are obvious when DB has more basic partMetas?
+ sharedBasicMetaIds = "58,629,1482,1493,1494,1495,1496,1497,566";//loadBasicAssetStructMetaId();
+
+ // fill allMetaIds with fixture partMetas
+ allMetaIds = getAllFixtureMetaIds();
+
+ // TODO: check if type of partMetas should be updated????
+ partMetas.put(assetStructNames.get(0), Map.of(language1, "Default string value1"));
+ //partMetas.put(assetStructNames.get(1), Map.of(language1, "Default string value2"));
+ partMetas.put(assetStructNames.get(2), Map.of(language1, "1111"));
+ //partMetas.put(assetStructNames.get(3), Map.of(language1, "1112"));
+ partMetas.put(assetStructNames.get(4), Map.of(language1, "01/01/2001"));
+ //partMetas.put(assetStructNames.get(5), Map.of(language1, "01/01/2002"));
+ partMetas.put(assetStructNames.get(6), Map.of(language1, "true"));
+ //partMetas.put(assetStructNames.get(7), Map.of(language1, "false"));
+
+ allMetas.putAll(partMetas);
+ allMetas.put(assetStructNames.get(1), Map.of(language1, "Default string value2"));
+ allMetas.put(assetStructNames.get(3), Map.of(language1, "1112"));
+ allMetas.put(assetStructNames.get(5), Map.of(language1, "01/01/2002"));
+ allMetas.put(assetStructNames.get(7), Map.of(language1, "false"));
+
+ allUpdatedMetas.putAll(allMetas);
+ allUpdatedMetas.put(assetStructNames.get(1), Map.of(language1, "Default string value22"));
+ allUpdatedMetas.put(assetStructNames.get(3), Map.of(language1, "11122"));
+ allUpdatedMetas.put(assetStructNames.get(5), Map.of(language1, "01/01/2022"));
+ allUpdatedMetas.put(assetStructNames.get(7), Map.of(language1, "true"));
+
+ // create shared assetStruct1
+ String prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss");
+ String metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedBasicMetaIds;
+ sharedAssetStruct1 = createAssetStruct(prefix, metaIds);
+
+ // create shared assetStruct2
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "2";
+ metaIds = sharedMetaString2.getMetaId().toString() + "," + sharedBasicMetaIds;
+ sharedAssetStruct2 = createAssetStruct(prefix, metaIds);
+ }
+
+ String getAllFixtureMetaIds() {
+ StringBuilder allMetaIdsSb = new StringBuilder();
+ allMetaIdsSb
+ .append(sharedMetaString1.getMetaId().toString())
+ .append(",")
+ .append(sharedMetaString2.getMetaId().toString())
+ .append(",")
+ .append(sharedMetaNumber1.getMetaId().toString())
+ .append(",")
+ .append(sharedMetaNumber2.getMetaId().toString())
+ .append(",")
+ .append(sharedMetaDate1.getMetaId().toString())
+ .append(",")
+ .append(sharedMetaDate2.getMetaId().toString())
+ .append(",")
+ .append(sharedMetaBoolean1.getMetaId().toString())
+ .append(",")
+ .append(sharedMetaBoolean2.getMetaId().toString());
+ return allMetaIdsSb.toString();
+ }
+
+ @Test
+ public void testAssetStructListSecurity() {
+ // assetStructList Master
+ AssetStructFilter filter = new AssetStructFilter();
+ ListAssetStructBuilder listAssetStructBuilder = AssetStructService.list(filter);
+ Response> assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(SharedHousehold.getSharedMasterUserKs()));
+ assertThat(assetStructListResponse.error.getMessage()).isEqualToIgnoringCase("Service Forbidden");
+
+ // assetStructList Operator
+ filter = new AssetStructFilter();
+ listAssetStructBuilder = AssetStructService.list(filter);
+ assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(getOperatorKs()));
+ assertThat(assetStructListResponse.results).isNotNull();
+ assertThat(assetStructListResponse.error).isNull();
+ }
+
+ @Test
+ public void testCreateInheritance() {
+ // create assetStruct1
+ String metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedBasicMetaIds;
+ String prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss");
+ AssetStruct assetStruct1 = createAssetStruct(prefix, metaIds);
+ // create assetStruct2
+ metaIds = sharedMetaString2.getMetaId().toString() + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "2";
+ AssetStruct assetStruct2 = createAssetStruct(prefix, metaIds);
+
+ // set inheritance
+ AssetStruct assetStruct2Update = copyAssetStructObject(assetStruct2);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStruct1.getId(),
+ sharedMetaString1.getMetaId(), sharedMetaString2.getMetaId());
+ updateAssetStruct(assetStruct2.getId(), assetStruct2Update, false);
+
+ // check parent doesn't have changes in related inheritance fields
+ AssetStructFilter filter = new AssetStructFilter();
+ filter.setIdIn(assetStruct1.getId().toString());
+ ListAssetStructBuilder listAssetStructBuilder = AssetStructService.list(filter);
+ Response> assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(getOperatorKs()));
+ AssetStruct assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+ assertThat(assetStructFromResponse.getParentId()).isEqualTo(0L);
+ assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(0L);
+ assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(0L);
+
+ // check children asset struct has changes
+ filter.setIdIn(assetStruct2.getId().toString());
+ listAssetStructBuilder = AssetStructService.list(filter);
+ assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(getOperatorKs()));
+ assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+ assertThat(assetStructFromResponse.getParentId()).isEqualTo(assetStruct1.getId());
+ assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(sharedMetaString1.getMetaId());
+ assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+
+ // remove assetStructs
+ deleteAssetStruct(assetStruct2.getId()); // firstly should be deleted children
+ deleteAssetStruct(assetStruct1.getId());
+ }
+
+ @Test(enabled = false) // TODO: remove after deletion
+ public void testInheritance4TextAndNumericFieldsOnly() {
+ // create assetStruct1
+ String metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedBasicMetaIds;
+ String prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss");
+ AssetStruct assetStruct1 = createAssetStruct(prefix, metaIds);
+ // create assetStruct2
+ metaIds = sharedMetaString2.getMetaId().toString() + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "2";
+ AssetStruct assetStruct2 = createAssetStruct(prefix, metaIds);
+
+ // set inheritance // to try set inheritance between different types of meta
+ AssetStruct assetStruct2Update = copyAssetStructObject(assetStruct2);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStruct1.getId(),
+ sharedMetaString1.getMetaId(), sharedMetaDate2.getMetaId());
+ updateAssetStruct(assetStruct2.getId(), assetStruct2Update, true);
+
+ // TODO: wait response from Anat and depends on it continue the test with other types
+ // check children asset struct has changes
+// AssetStructFilter filter = new AssetStructFilter();
+// filter.setIdIn(assetStruct2.getId().toString());
+// ListAssetStructBuilder listAssetStructBuilder = AssetStructService.list(filter);
+// Response> assetStructListResponse = executor.executeSync(listAssetStructBuilder
+// .setKs(getOperatorKs()));
+// AssetStruct assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+// assertThat(assetStructFromResponse.getParentId()).isEqualTo(assetStruct1.getId());
+// assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(sharedMetaString1.getMetaId());
+// assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+
+ // remove assetStructs
+ deleteAssetStruct(assetStruct2.getId()); // firstly should be deleted children
+ deleteAssetStruct(assetStruct1.getId());
+ }
+
+ @Test
+ public void testInheritance3Levels() {
+ // create granpa
+ String metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedBasicMetaIds;
+ String prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss");
+ AssetStruct assetStructGrandParent = createAssetStruct(prefix, metaIds);
+ // create parent
+ metaIds = sharedMetaString2.getMetaId().toString() + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "2";
+ AssetStruct assetStructParent = createAssetStruct(prefix, metaIds);
+ // create children
+ metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedMetaString2.getMetaId().toString() + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "3";
+ AssetStruct assetStructChildren = createAssetStruct(prefix, metaIds);
+
+ // set inheritance between Children and Parent
+ AssetStruct assetStruct2Update = copyAssetStructObject(assetStructChildren);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStructParent.getId(),
+ sharedMetaString2.getMetaId(), sharedMetaDate2.getMetaId());
+ updateAssetStruct(assetStructChildren.getId(), assetStruct2Update, false);
+
+ // set inheritance between Parent and GrandParent
+ assetStruct2Update = copyAssetStructObject(assetStructParent);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStructGrandParent.getId(),
+ sharedMetaString1.getMetaId(), sharedMetaDate2.getMetaId());
+ updateAssetStruct(assetStructParent.getId(), assetStruct2Update, false);
+
+ // check children asset struct has changes
+ AssetStructFilter filter = new AssetStructFilter();
+ filter.setIdIn(assetStructChildren.getId().toString());
+ ListAssetStructBuilder listAssetStructBuilder = AssetStructService.list(filter);
+ Response> assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(getOperatorKs()));
+ AssetStruct assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+ assertThat(assetStructFromResponse.getParentId()).isEqualTo(assetStructParent.getId());
+ assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+ assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+
+ // check parent asset struct has changes
+ filter = new AssetStructFilter();
+ filter.setIdIn(assetStructParent.getId().toString());
+ listAssetStructBuilder = AssetStructService.list(filter);
+ assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(getOperatorKs()));
+ assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+ assertThat(assetStructFromResponse.getParentId()).isEqualTo(assetStructGrandParent.getId());
+ assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(sharedMetaString1.getMetaId());
+ assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+
+ // remove assetStructs
+ deleteAssetStruct(assetStructChildren.getId()); // firstly should be deleted children
+ deleteAssetStruct(assetStructParent.getId()); // secondly should be deleted parent
+ deleteAssetStruct(assetStructGrandParent.getId());
+ }
+
+ // checking that on BE level it is doesn't supported limitation about 1 children maximum
+ @Test
+ public void testInheritanceParentWith2Childrens() {
+ // create parent
+ String metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedBasicMetaIds;
+ String prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss");
+ AssetStruct assetStructParent = createAssetStruct(prefix, metaIds);
+ // create children1
+ metaIds = sharedMetaString2.getMetaId().toString() + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "2";
+ AssetStruct assetStructChildren1 = createAssetStruct(prefix, metaIds);
+ // create children2
+ metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedMetaString2.getMetaId().toString() + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "3";
+ AssetStruct assetStructChildren2 = createAssetStruct(prefix, metaIds);
+
+ // set inheritance between Children2 and Parent
+ AssetStruct assetStruct2Update = copyAssetStructObject(assetStructChildren2);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStructParent.getId(),
+ sharedMetaString1.getMetaId(), sharedMetaDate2.getMetaId());
+ updateAssetStruct(assetStructChildren2.getId(), assetStruct2Update, false);
+
+ // set inheritance between Children1 and Parent
+ assetStruct2Update = copyAssetStructObject(assetStructChildren1);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStructParent.getId(),
+ sharedMetaString1.getMetaId(), sharedMetaDate2.getMetaId());
+ updateAssetStruct(assetStructChildren1.getId(), assetStruct2Update, false);
+
+ // check children asset2 struct has changes
+ AssetStructFilter filter = new AssetStructFilter();
+ filter.setIdIn(assetStructChildren2.getId().toString());
+ ListAssetStructBuilder listAssetStructBuilder = AssetStructService.list(filter);
+ Response> assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(getOperatorKs()));
+ AssetStruct assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+ assertThat(assetStructFromResponse.getParentId()).isEqualTo(assetStructParent.getId());
+ assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(sharedMetaString1.getMetaId());
+ assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+
+ // check children asset1 struct has changes
+ filter = new AssetStructFilter();
+ filter.setIdIn(assetStructChildren1.getId().toString());
+ listAssetStructBuilder = AssetStructService.list(filter);
+ assetStructListResponse = executor.executeSync(listAssetStructBuilder
+ .setKs(getOperatorKs()));
+ assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+ assertThat(assetStructFromResponse.getParentId()).isEqualTo(assetStructParent.getId());
+ assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(sharedMetaString1.getMetaId());
+ assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+
+ // remove assetStructs
+ deleteAssetStruct(assetStructChildren2.getId()); // firstly should be deleted childrens
+ deleteAssetStruct(assetStructChildren1.getId()); // firstly should be deleted childrens
+ deleteAssetStruct(assetStructParent.getId());
+ }
+
+ @Test // TODO: wait response from Anat why children wasn't changed
+ public void testInheritanceWithIngest() {
+ // create parent
+ String metaIds = allMetaIds + "," + sharedBasicMetaIds;
+ String prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss");
+ AssetStruct assetStructParent = createAssetStruct(prefix, metaIds);
+ // create children1
+ metaIds = allMetaIds + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "2";
+ AssetStruct assetStructChildren = createAssetStruct(prefix, metaIds);
+
+ // set inheritance between Children and Parent
+ AssetStruct assetStruct2Update = copyAssetStructObject(assetStructChildren);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStructParent.getId(),
+ sharedMetaString1.getMetaId(), sharedMetaString1.getMetaId());
+ updateAssetStruct(assetStructChildren.getId(), assetStruct2Update, false);
+
+ // ingest all metas of needed type // TODO: it does not work with NULL - discuss with Alon what MediaType use instead of it
+ IngestVodUtils.VodData parentVodData = getVodData(MediaType.PACKAGE, INSERT)
+ .multilingualStringsMeta(partMetas)
+ .customMediaType(assetStructParent.getSystemName());
+ MediaAsset parentAsset = insertVod(parentVodData, false);
+ assertThat(parentAsset.getExternalId()).isNotNull();
+
+ IngestVodUtils.VodData childrenVodData = getVodData(MediaType.PACKAGE, INSERT)
+ .multilingualStringsMeta(allMetas)
+ .customMediaType(assetStructChildren.getSystemName());
+ MediaAsset childrenAsset = insertVod(childrenVodData, false);
+ assertThat(childrenAsset.getExternalId()).isNotNull();
+ // TODO: check metas on children
+
+ String coguid = parentAsset.getExternalId();
+ parentVodData = new IngestVodUtils.VodData()
+ .multilingualStringsMeta(allUpdatedMetas)
+ .customMediaType(assetStructParent.getSystemName());
+ parentAsset = updateVod(coguid, parentVodData);
+
+ // TODO: check metas on children after parent update
+
+ AssetService.GetAssetBuilder getAssetBuilder = AssetService.get(childrenAsset.getId().toString(), AssetReferenceType.MEDIA);
+ Response assetResponse = executor.executeSync(getAssetBuilder
+ .setKs(getOperatorKs()));
+ assertThat(assetResponse.results).isNotNull();
+
+ // remove assetStructs
+ deleteVod(childrenAsset.getExternalId());
+ deleteVod(parentAsset.getExternalId());
+ deleteAssetStruct(assetStructChildren.getId()); // firstly should be deleted children
+ deleteAssetStruct(assetStructParent.getId());
+ }
+
+// @Test //TODO: after ingest
+// public void testIngestRules() {
+// IngestVodUtils.VodData vodData = getVodData(SERIES, INSERT);
+// MediaAsset series = insertVod(vodData, true);
+// assertThat(series.getExternalId()).isNotNull();
+//
+// vodData = getVodData(EPISODE, INSERT);
+// MediaAsset episode = insertVod(vodData, true);
+// assertThat(episode.getExternalId()).isNotNull();
+//
+// vodData = getVodData(MOVIE, INSERT);
+// MediaAsset movie = insertVod(vodData, true);
+// assertThat(movie.getExternalId()).isNotNull();
+//
+// vodData = getVodData(LINEAR, INSERT);
+// MediaAsset linear = insertVod(vodData, true);
+// assertThat(linear.getExternalId()).isNotNull();
+//
+// System.out.println("SERIES POLICY: " + series.getInheritancePolicy().getValue());
+// System.out.println("EPISODE POLICY: " + episode.getInheritancePolicy().getValue());
+// System.out.println("MOVIE POLICY: " + movie.getInheritancePolicy().getValue());
+// System.out.println("LINEAR POLICY: " + linear.getInheritancePolicy().getValue());
+//
+// // cleanup
+// deleteVod(linear.getExternalId());
+// deleteVod(movie.getExternalId());
+// deleteVod(series.getExternalId());
+// deleteVod(episode.getExternalId());
+// }
+
+ @Test
+ public void testApiCreationOfAssetsWithInheritance() {
+ // create parent
+ String metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedBasicMetaIds;
+ String prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss");
+ AssetStruct assetStructParent = createAssetStruct(prefix, metaIds);
+ // create children
+ metaIds = sharedMetaString1.getMetaId().toString() + "," + sharedBasicMetaIds;
+ prefix = "AssetStruct_" + getCurrentDateInFormat("yyMMddHHmmss") + "2";
+ AssetStruct assetStructChildren = createAssetStruct(prefix, metaIds);
+ Map metas = new HashMap<>();
+ metas.put(DBUtils.getMetaNameById(sharedMetaString1.getMetaId(), false), "some default value");
+ // set inheritance between Children and Parent
+ AssetStruct assetStruct2Update = copyAssetStructObject(assetStructChildren);
+ setInheritanceFieldsInAssetStruct(assetStruct2Update, assetStructParent.getId(),
+ sharedMetaString1.getMetaId(), sharedMetaDate2.getMetaId());
+ updateAssetStruct(assetStructChildren.getId(), assetStruct2Update, false);
+
+ // TODO: complete
+ MediaAsset asset = getMediaAsset(assetStructParent.getId(), "testName", "testDescription");
+ asset.setMetas(loadMetas(metas));
+ AssetService.AddAssetBuilder addAssetBuilder = AssetService.add(asset);
+ Response response = executor.executeSync(addAssetBuilder
+ .setKs(getOperatorKs())
+ .setLanguage("*"));
+ asset = (MediaAsset) response.results;
+
+ MediaAsset asset2 = getMediaAsset(assetStructChildren.getId(), "testName2", "testDescription2");
+ asset2.setMetas(loadMetas(metas));
+ addAssetBuilder = AssetService.add(asset2);
+ response = executor.executeSync(addAssetBuilder
+ .setKs(getOperatorKs())
+ .setLanguage("*"));
+ asset2 = (MediaAsset) response.results;
+//
+// // check children asset1 struct has changes
+// AssetStructFilter filter = new AssetStructFilter();
+// filter.setIdIn(assetStructChildren.getId().toString());
+// ListAssetStructBuilder listAssetStructBuilder = AssetStructService.list(filter);
+// Response> assetStructListResponse = executor.executeSync(listAssetStructBuilder
+// .setKs(getOperatorKs()));
+// AssetStruct assetStructFromResponse = assetStructListResponse.results.getObjects().get(0);
+// assertThat(assetStructFromResponse.getParentId()).isEqualTo(assetStructParent.getId());
+// assertThat(assetStructFromResponse.getConnectedParentMetaId()).isEqualTo(sharedMetaString1.getMetaId());
+// assertThat(assetStructFromResponse.getConnectingMetaId()).isEqualTo(sharedMetaString2.getMetaId());
+
+ // 4rent folder has some logic
+
+ // remove assetStructs
+ deleteVod(asset.getExternalId());
+ deleteVod(asset2.getExternalId());
+ deleteAssetStruct(assetStructChildren.getId()); // firstly should be deleted children
+ deleteAssetStruct(assetStructParent.getId());
+ }
+
+ // TODO: find better name and option to use it in the whole project
+ private Map loadMetas(Map metas) {
+ Map result = new HashMap<>();
+ for (Map.Entry entry: metas.entrySet()) {
+ StringValue value = new StringValue();
+ value.setValue(entry.getValue());
+ //value.value(entry.getValue());
+ result.put(entry.getKey(), value);
+ }
+
+ return result;
+ }
+
+
+ // TODO: Check if it used after implementation
+ private List loadAssetStructsWithoutHierarchy(int countOfAssetStructs, List listOfAssetStructs) {
+ List result = new ArrayList<>();
+ for (AssetStruct assetStruct: listOfAssetStructs) {
+ if ((result.size() < countOfAssetStructs) && (assetStruct.getParentId() == 0)) {
+ result.add(assetStruct);
+ }
+ }
+ return result;
+ }
+
+ // added to play with methods that are going to be checked
+// @Test
+// public void sandbox() {
+// String prefix = "MaxTest_assetStruct_";
+//
+// Long assetStructId = sharedAssetStructListResponse.results.getObjects().get(0).getId();
+//
+// AssetStructMetaFilter assetStructMetaFilter = new AssetStructMetaFilter();
+// assetStructMetaFilter.setAssetStructIdEqual(assetStructId);
+// ListAssetStructMetaBuilder listAssetStructMetaBuilder = AssetStructMetaService.list(assetStructMetaFilter);
+// Response> listAssetMetaStructResponse = executor.executeSync(listAssetStructMetaBuilder
+// .setKs(getOperatorKs()));
+// assertThat(listAssetMetaStructResponse.results.getTotalCount()).isGreaterThan(0);
+// Long metaId = listAssetMetaStructResponse.results.getObjects().get(0).getMetaId();
+//
+// String defaultIngestValue = prefix + "_defaultIngestValue";
+// String ingestReferencePath = prefix + "ingestReferencePath";
+// boolean isProtectFromIngest = false;
+// boolean isInherited = true;
+// AssetStructMeta assetStructMeta = getAssetStructMeta(defaultIngestValue,
+// ingestReferencePath, isProtectFromIngest, isInherited);
+// UpdateAssetStructMetaBuilder updateAssetStructMetaBuilder =
+// new UpdateAssetStructMetaBuilder(assetStructId, metaId, assetStructMeta);
+// Response assetStructMetaResponse = executor.executeSync(updateAssetStructMetaBuilder
+// .setKs(getOperatorKs()));
+// assertThat(assetStructMetaResponse.results.getAssetStructId()).isEqualTo(assetStructId);
+// assertThat(assetStructMetaResponse.results.getMetaId()).isEqualTo(metaId);
+// assertThat(assetStructMetaResponse.results.getDefaultIngestValue()).isEqualToIgnoringCase(defaultIngestValue);
+// assertThat(assetStructMetaResponse.results.getIngestReferencePath()).isEqualToIgnoringCase(ingestReferencePath);
+// assertThat(assetStructMetaResponse.results.getProtectFromIngest()).isEqualTo(isProtectFromIngest);
+// //TODO: update library to have options compare it
+// //assertThat(assetStructMetaResponse.results.getInherited()).isEqualTo(isInherited);
+//
+// // assetStructAdd
+// AssetStruct assetStruct = getAssetStruct(prefix, DEFAULT_LANGUAGE, false, metaIds, null, null, null);
+// AddAssetStructBuilder addAssetStructBuilder = AssetStructService.add(assetStruct);
+// Response assetStructResponse = executor.executeSync(addAssetStructBuilder
+// .setKs(getOperatorKs()).setLanguage("*"));
+// AssetStruct assetStructFromResponse = assetStructResponse.results;
+// assertThat(assetStructResponse.results.getSystemName()).isEqualToIgnoringCase(prefix + "_System_name");
+//
+// assetStruct.setSystemName(prefix + "_System_name_upd");
+//
+// // assetStructUpdate
+// UpdateAssetStructBuilder updateAssetStructBuilder = AssetStructService.update(assetStructFromResponse.getId(), assetStruct);
+// assetStructResponse = executor.executeSync(updateAssetStructBuilder
+// .setKs(getOperatorKs())
+// .setLanguage("*"));
+// assertThat(assetStructResponse.results.getSystemName()).isEqualToIgnoringCase(prefix + "_System_name_upd");
+//
+// // assetStructDelete
+// DeleteAssetStructBuilder deleteAssetStructBuilder = AssetStructService.delete(assetStructFromResponse.getId());
+// Response deleteAssetStructResponse = executor.executeSync(deleteAssetStructBuilder
+// .setKs(getOperatorKs()));
+// assertThat(deleteAssetStructResponse.results.booleanValue()).isEqualTo(true);
+// }
+
+// @Test
+// public void sandboxRemoveMetasAndTags() {
+// IngestVodUtils.VodData vodData = getVodData(MOVIE, INSERT);
+// MediaAsset movie = insertVod(vodData, true);
+//
+// assertThat(movie.getName()).isEqualTo(movie.getExternalId());
+// assertThat(movie.getDescription()).isEqualTo("description of " + movie.getExternalId());
+// // get all metas
+// Set movieMetasNames = movie.getMetas().keySet();
+// int metasSizeAfterCreation = movieMetasNames.size();
+// int nonBasicMediaMetasCount = 0;
+// assertThat(metasSizeAfterCreation).isGreaterThan(0);
+//
+// // get all tags
+// Set movieTagsNames = movie.getTags().keySet();
+// int tagsSizeAfterCreation = movieTagsNames.size();
+// assertThat(tagsSizeAfterCreation).isGreaterThan(0);
+//
+// // get all metas and tags info to remove them from media
+// List metaIds = new ArrayList<>();
+// int metaId;
+// for (String metaName: movieMetasNames) {
+// metaId = getMetaIdByName(metaName, false);
+// if (metaId !=-1) {
+// metaIds.add(String.valueOf(metaId));
+// nonBasicMediaMetasCount++;
+// }
+// }
+// for (String metaName: movieTagsNames) {
+// metaId = getMetaIdByName(metaName, true);
+// if (metaId !=-1) {
+// metaIds.add(String.valueOf(metaId));
+// }
+// }
+// String metaIdsIn = String.join(",", metaIds);
+//
+// // removeMetasAndTags
+// RemoveMetasAndTagsAssetBuilder removeMetasAndTagsAssetBuilder =
+// AssetService.removeMetasAndTags(movie.getId(), AssetReferenceType.MEDIA, metaIdsIn);
+// Response booleanResponse = executor.executeSync(removeMetasAndTagsAssetBuilder
+// .setKs(getOperatorKs()));
+// assertThat(booleanResponse.results).isEqualTo(true);
+//
+// // check results
+// GetAssetBuilder getAssetBuilder = AssetService.get(movie.getId().toString(), AssetReferenceType.MEDIA);
+// Response assetResponse = executor.executeSync(getAssetBuilder
+// .setKs(getOperatorKs()));
+// movie = (MediaAsset) assetResponse.results;
+//
+// assertThat(movie.getName()).isEqualTo(movie.getExternalId());
+// assertThat(movie.getDescription()).isEqualTo("description of " + movie.getExternalId());
+// assertThat(movie.getMetas().keySet().size()).isEqualTo(metasSizeAfterCreation - nonBasicMediaMetasCount);
+// assertThat(movie.getTags().keySet().size()).isEqualTo(0);
+//
+// // cleanup
+// deleteVod(movie.getExternalId());
+// }
+
+// @Test
+// public void sandboxDelete() {
+// DeleteAssetStructBuilder deleteAssetStructBuilder = AssetStructService.delete(2381);
+// Response deleteAssetStructResponse = executor.executeSync(deleteAssetStructBuilder
+// .setKs(getOperatorKs()));
+// assertThat(deleteAssetStructResponse.results.booleanValue()).isEqualTo(true);
+// }
+
+ @AfterClass()
+ public void tearDown() {
+ // cleaning created shared assetStructs
+ deleteAssetStruct(sharedAssetStruct1.getId());
+ deleteAssetStruct(sharedAssetStruct2.getId());
+ }
+
+ void deleteAssetStruct(Long assetStructId) {
+ DeleteAssetStructBuilder deleteAssetStructBuilder = AssetStructService.delete(assetStructId);
+ Response deleteAssetStructResponse = executor.executeSync(deleteAssetStructBuilder
+ .setKs(getOperatorKs()));
+ assertThat(deleteAssetStructResponse.results.booleanValue()).isEqualTo(true);
+ }
+
+ AssetStruct createAssetStruct(String prefix, String metaIds) {
+ AssetStruct result = getAssetStruct(prefix, DEFAULT_LANGUAGE, false, metaIds, null,
+ null, null);
+
+ AddAssetStructBuilder addAssetStructBuilder = AssetStructService.add(result);
+ Response assetStructResponse = executor.executeSync(addAssetStructBuilder
+ .setKs(getOperatorKs()).setLanguage("*"));
+ result = assetStructResponse.results;
+
+ assertThat(result.getSystemName()).isEqualToIgnoringCase(prefix + "_System_name");
+
+ return result;
+ }
+
+ Response updateAssetStruct(Long assetStructId, AssetStruct updatedAssetStruct, boolean isErrorExpected) {
+ UpdateAssetStructBuilder updateAssetStructBuilder = AssetStructService.update(
+ assetStructId, updatedAssetStruct);
+ Response assetStructResponse = executor.executeSync(updateAssetStructBuilder
+ .setKs(getOperatorKs()).setLanguage("*"));
+ if (isErrorExpected) {
+ assertThat(assetStructResponse.error).isNotNull();
+ } else {
+ assertThat(assetStructResponse.results).isNotNull();
+ }
+
+ return assetStructResponse;
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/five_zero_two/IngestVodOpcTests.java b/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/five_zero_two/IngestVodOpcTests.java
new file mode 100644
index 000000000..bd2d88a5d
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/five_zero_two/IngestVodOpcTests.java
@@ -0,0 +1,652 @@
+package com.kaltura.client.test.tests.featuresTests.versions.five_zero_two;
+
+import com.kaltura.client.enums.AssetReferenceType;
+import com.kaltura.client.services.LanguageService;
+import com.kaltura.client.services.PpvService;
+import com.kaltura.client.services.ProductPriceService;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.utils.BaseUtils;
+import com.kaltura.client.test.utils.KsqlBuilder;
+import com.kaltura.client.test.utils.dbUtils.DBUtils;
+import com.kaltura.client.types.*;
+import io.qameta.allure.Issue;
+import io.qameta.allure.Link;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import io.restassured.response.Response;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.stream.Collectors;
+
+import static com.kaltura.client.services.AssetService.*;
+import static com.kaltura.client.services.AssetService.get;
+import static com.kaltura.client.test.tests.enums.IngestAction.*;
+import static com.kaltura.client.test.tests.enums.KsqlKey.MEDIA_ID;
+import static com.kaltura.client.test.tests.enums.MediaType.*;
+import static com.kaltura.client.test.utils.BaseUtils.*;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodOpcUtils.delayBetweenRetriesInSeconds;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodOpcUtils.*;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodOpcUtils.maxTimeExpectingValidResponseInSeconds;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.*;
+import static io.restassured.path.xml.XmlPath.from;
+import static java.util.TimeZone.getTimeZone;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+import static org.awaitility.Awaitility.await;
+
+/**
+ *
+ * Class to test functionality described in https://kaltura.atlassian.net/browse/BEO-5428
+ */
+@Link(name = "OPC VOD Ingest", url = "BEO-5428")
+@Test(groups = { "opc", "OPC VOD Ingest" })
+public class IngestVodOpcTests extends BaseTest {
+ private int movieType;
+ private int episodeType;
+ private int seriesType;
+
+ @BeforeClass()
+ public void ingestVodOpcTests_beforeClass() {
+ movieType = DBUtils.getMediaTypeId(MOVIE);
+ episodeType = DBUtils.getMediaTypeId(EPISODE);
+ seriesType = DBUtils.getMediaTypeId(SERIES);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "ingest VOD with filled base meta fields")
+ public void insertVodMediaTagFieldName() {
+ VodData vodData = getVodData(MOVIE, INSERT);
+ MediaAsset movie = insertVod(vodData, true);
+
+ assertThat(movie.getName()).isEqualTo(vodData.name());
+ assertThat(movie.getDescription()).isEqualTo(vodData.description());
+ assertThat(((MultilingualStringValue)movie.getMetas().get(mediaTextFieldName)).getValue()).isEqualTo(vodData.stringsMeta().get(mediaTextFieldName));
+ assertThat(((DoubleValue)movie.getMetas().get(mediaNumberFieldName)).getValue()).isEqualTo(vodData.numbersMeta().get(mediaNumberFieldName));
+ assertThat(getFormattedDate(((LongValue)movie.getMetas().get(mediaDateFieldName)).getValue(), getTimeZone("UTC"), "MM/dd/yyyy")).isEqualTo(vodData.datesMeta().get(mediaDateFieldName));
+ assertThat(((BooleanValue)movie.getMetas().get(mediaBooleanFieldName)).getValue()).isEqualTo(vodData.booleansMeta().get(mediaBooleanFieldName));
+ assertThat(movie.getTags().get(mediaTagFieldName).getObjects()).extracting("value").containsExactlyElementsOf(vodData.tags().get(mediaTagFieldName));
+ assertFiles(vodData.files(), movie.getId().toString());
+ assertThat(movie.getImages()).extracting("ratio").containsAll(vodData.thumbRatios());
+
+ // cleanup
+ deleteVod(movie.getExternalId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "update VOD with filled base meta fields and erase = true")
+ public void updateVodMediaBaseFieldsWithErase() {
+ String coguid = getCoguidOfActiveMediaAsset(movieType);
+ VodData vodData = new VodData()
+ .name(String.valueOf(getEpochInMillis()))
+ .isErase(true);
+
+ MediaAsset movie = updateVod(coguid, vodData);
+
+ assertThat(movie.getName()).isEqualTo(vodData.name());
+ assertThat(movie.getDescription()).isEqualTo("");
+
+ fail("ask Shir why some of the old data return while some being delete as expected");
+
+// assertThat(((MultilingualStringValue)movie.getMetas().get(mediaTextFieldName)).getValue()).isEqualTo(vodData.strings().get(mediaTextFieldName));
+// assertThat(((DoubleValue)movie.getMetas().get(mediaNumberFieldName)).getValue()).isEqualTo(vodData.numbers().get(mediaNumberFieldName));
+// assertThat(getFormattedDate(((LongValue)movie.getMetas().get(mediaDateFieldName)).getValue(), getTimeZone("UTC"), "MM/dd/yyyy")).isEqualTo(vodData.dates().get(mediaDateFieldName));
+// assertThat(((BooleanValue)movie.getMetas().get(mediaBooleanFieldName)).getValue()).isEqualTo(vodData.booleans().get(mediaBooleanFieldName));
+// assertThat(movie.getTags().get(mediaTagFieldName).getObjects()).extracting("value").containsExactlyElementsOf(vodData.tags().get(mediaTagFieldName));
+// assertFiles(vodData.files(), movie.getId().toString());
+// assertThat(movie.getImages()).extracting("ratio").containsAll(vodData.thumbRatios());
+
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "update VOD with filled base meta fields and erase = false")
+ public void updateVodMediaBaseFieldsWithoutErase() {
+ String coguid = getCoguidOfActiveMediaAsset(movieType);
+ VodData vodData = getVodData(MOVIE, UPDATE);
+
+ MediaAsset movie = updateVod(coguid, vodData);
+
+ assertThat(movie.getName()).isEqualTo(vodData.name());
+ assertThat(movie.getDescription()).isEqualTo(vodData.description());
+ assertThat(((MultilingualStringValue)movie.getMetas().get(mediaTextFieldName)).getValue()).isEqualTo(vodData.stringsMeta().get(mediaTextFieldName));
+ assertThat(((DoubleValue)movie.getMetas().get(mediaNumberFieldName)).getValue()).isEqualTo(vodData.numbersMeta().get(mediaNumberFieldName));
+ assertThat(getFormattedDate(((LongValue)movie.getMetas().get(mediaDateFieldName)).getValue(), getTimeZone("UTC"), "MM/dd/yyyy")).isEqualTo(vodData.datesMeta().get(mediaDateFieldName));
+ assertThat(((BooleanValue)movie.getMetas().get(mediaBooleanFieldName)).getValue()).isEqualTo(vodData.booleansMeta().get(mediaBooleanFieldName));
+ assertThat(movie.getTags().get(mediaTagFieldName).getObjects()).extracting("value").containsExactlyElementsOf(vodData.tags().get(mediaTagFieldName));
+ assertFiles(vodData.files(), movie.getId().toString());
+ assertThat(movie.getImages()).extracting("ratio").containsAll(vodData.thumbRatios());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "ingest VOD with filled base meta fields")
+ public void insertVodEpisodeBaseFields() {
+ VodData vodData = getVodData(EPISODE, INSERT);
+ MediaAsset episode = insertVod(vodData, true);
+
+ assertThat(episode.getName()).isEqualTo(vodData.name());
+ assertThat(episode.getDescription()).isEqualTo(vodData.description());
+ assertThat(((MultilingualStringValue) episode.getMetas().get(episodeTextFieldName)).getValue()).isEqualTo(vodData.stringsMeta().get(episodeTextFieldName));
+ assertThat(((DoubleValue) episode.getMetas().get(episodeNumberFieldName)).getValue()).isEqualTo(vodData.numbersMeta().get(episodeNumberFieldName));
+ assertThat(getFormattedDate(((LongValue) episode.getMetas().get(episodeDateFieldName)).getValue(), getTimeZone("UTC"), "MM/dd/yyyy")).isEqualTo(vodData.datesMeta().get(episodeDateFieldName));
+ assertThat(((BooleanValue) episode.getMetas().get(episodeBooleanFieldName)).getValue()).isEqualTo(vodData.booleansMeta().get(episodeBooleanFieldName));
+ assertThat(episode.getTags().get(episodeTagFieldName).getObjects()).extracting("value").containsExactlyElementsOf(vodData.tags().get(episodeTagFieldName));
+ assertFiles(vodData.files(), episode.getId().toString());
+ assertThat(episode.getImages()).extracting("ratio").containsAll(vodData.thumbRatios());
+
+ // cleanup
+ deleteVod(episode.getExternalId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "ingest VOD with filled base meta fields")
+ public void insertVodSeriesBaseFields() {
+ VodData vodData = getVodData(SERIES, INSERT);
+ MediaAsset series = insertVod(vodData, true);
+
+ assertThat(series.getName()).isEqualTo(vodData.name());
+ assertThat(series.getDescription()).isEqualTo(vodData.description());
+ assertThat(((StringValue) series.getMetas().get(seriesTextFieldName)).getValue()).isEqualTo(vodData.stringsMeta().get(seriesTextFieldName));
+ assertThat(((DoubleValue) series.getMetas().get(seriesNumberFieldName)).getValue()).isEqualTo(vodData.numbersMeta().get(seriesNumberFieldName));
+ assertThat(getFormattedDate(((LongValue) series.getMetas().get(seriesDateFieldName)).getValue(), getTimeZone("UTC"), "MM/dd/yyyy")).isEqualTo(vodData.datesMeta().get(seriesDateFieldName));
+ assertThat(((BooleanValue) series.getMetas().get(seriesBooleanFieldName)).getValue()).isEqualTo(vodData.booleansMeta().get(seriesBooleanFieldName));
+ assertThat(series.getTags().get(seriesTagFieldName).getObjects()).extracting("value").containsExactlyElementsOf(vodData.tags().get(seriesTagFieldName));
+ assertFiles(vodData.files(), series.getId().toString());
+ assertThat(series.getImages()).extracting("ratio").containsAll(vodData.thumbRatios());
+
+ // cleanup
+ deleteVod(series.getExternalId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "update VOD episode with filled base meta fields")
+ public void updateVodEpisodeBaseFields() {
+ VodData vodData = getVodData(EPISODE, UPDATE);
+
+ String coguid = getCoguidOfActiveMediaAsset(episodeType);
+ MediaAsset episode = updateVod(coguid, vodData);
+
+ assertThat(episode.getName()).isEqualTo(vodData.name());
+ assertThat(episode.getDescription()).isEqualTo(vodData.description());
+ assertThat(((MultilingualStringValue) episode.getMetas().get(episodeTextFieldName)).getValue()).isEqualTo(vodData.stringsMeta().get(episodeTextFieldName));
+ assertThat(((DoubleValue) episode.getMetas().get(episodeNumberFieldName)).getValue()).isEqualTo(vodData.numbersMeta().get(episodeNumberFieldName));
+ assertThat(getFormattedDate(((LongValue) episode.getMetas().get(episodeDateFieldName)).getValue(), getTimeZone("UTC"), "MM/dd/yyyy")).isEqualTo(vodData.datesMeta().get(episodeDateFieldName));
+ assertThat(((BooleanValue) episode.getMetas().get(episodeBooleanFieldName)).getValue()).isEqualTo(vodData.booleansMeta().get(episodeBooleanFieldName));
+ assertThat(episode.getTags().get(episodeTagFieldName).getObjects()).extracting("value").containsExactlyElementsOf(vodData.tags().get(episodeTagFieldName));
+// assertFiles(vodData.files(), episode.getId().toString());
+ assertThat(episode.getImages()).extracting("ratio").containsAll(vodData.thumbRatios());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "update VOD series with filled base meta fields")
+ public void updateVodSeriesBaseFields() {
+ VodData vodData = getVodData(SERIES, UPDATE);
+
+ String coguid = getCoguidOfActiveMediaAsset(seriesType);
+ MediaAsset series = updateVod(coguid, vodData);
+
+ assertThat(series.getName()).isEqualTo(vodData.name());
+ assertThat(series.getDescription()).isEqualTo(vodData.description());
+ assertThat(((StringValue) series.getMetas().get(seriesTextFieldName)).getValue()).isEqualTo(vodData.stringsMeta().get(seriesTextFieldName));
+ assertThat(((DoubleValue) series.getMetas().get(seriesNumberFieldName)).getValue()).isEqualTo(vodData.numbersMeta().get(seriesNumberFieldName));
+ assertThat(getFormattedDate(((LongValue) series.getMetas().get(seriesDateFieldName)).getValue(), getTimeZone("UTC"), "MM/dd/yyyy")).isEqualTo(vodData.datesMeta().get(seriesDateFieldName));
+ assertThat(((BooleanValue) series.getMetas().get(seriesBooleanFieldName)).getValue()).isEqualTo(vodData.booleansMeta().get(seriesBooleanFieldName));
+ assertThat(series.getTags().get(seriesTagFieldName).getObjects()).extracting("value").containsExactlyElementsOf(vodData.tags().get(seriesTagFieldName));
+// assertFiles(vodData.files(), series.getId().toString());
+ assertThat(series.getImages()).extracting("ratio").containsAll(vodData.thumbRatios());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "delete movie")
+ public void deleteMovie() {
+ String coguid = getCoguidOfActiveMediaAsset(movieType);
+ assertVodDeletion(coguid);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "delete episode")
+ public void deleteEpisode() {
+ String coguid = getCoguidOfActiveMediaAsset(episodeType);
+ assertVodDeletion(coguid);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "delete series")
+ public void deleteSeries() {
+ String coguid = getCoguidOfActiveMediaAsset(seriesType);
+ assertVodDeletion(coguid);
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "try insert without coguid")
+ public void insertWithEmptyCoguid() {
+ // insert with empty coguid
+ VodData vodData = getVodData(MOVIE, INSERT).coguid("");
+ String invalidXml = buildIngestVodXml(vodData, INSERT);
+ Response resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath)).contains("External identifier is missing");
+
+ // insert without coguid attribute
+ invalidXml = invalidXml.replaceAll("co_guid=\"\"", "");
+ resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath)).contains("External identifier is missing");
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "try delete without coguid")
+ public void deleteWithEmptyCoguid() {
+ // delete with empty coguid
+ String invalidXml = buildIngestVodXml(new VodData(), DELETE);
+ Response resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath)).contains("External identifier is missing");
+
+ // delete with missing coguid attribute
+ invalidXml = invalidXml.replaceAll("co_guid=\"\"", "");
+ resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath)).contains("External identifier is missing");
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "try delete with non-existed coguid")
+ public void deleteWithNonExistedCoguid() {
+ String invalidCoguid = "123456";
+ VodData vodData = new VodData().coguid(invalidCoguid);
+ String invalidXml = buildIngestVodXml(vodData, DELETE);
+ Response resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusWarningMessagePath)).contains("Media Id not exist");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "try insert with empty entry_id")
+ public void insertWithEmptyEntryId() {
+ VodData vodData = getVodData(MOVIE, INSERT);
+ String ingestInsertXml = buildIngestVodXml(vodData, INSERT);
+
+ // entry_id tag empty
+ String invalidXml = ingestInsertXml.replaceAll("entry_id=\"entry_" + vodData.coguid() + "\"", "entry_id=\"\"");
+ Response resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusWarningMessagePath)).contains("entry_id is missing");
+
+ // without entry_id tag
+ invalidXml = ingestInsertXml.replaceAll("entry_id=\"entry_" + vodData.coguid() + "\"", "");
+ resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusWarningMessagePath)).contains("entry_id is missing");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "try insert inactive item")
+ public void insertInactiveItem() {
+ VodData vodData = getVodData(MOVIE, INSERT).isActive(false);
+ String invalidXml = buildIngestVodXml(vodData, INSERT);
+
+ Response resp = executeIngestVodRequest(invalidXml);
+ String id = from(resp.asString()).get(ingestAssetIdPath).toString();
+
+ SearchAssetFilter assetFilter = new SearchAssetFilter();
+ String query = new KsqlBuilder().equal(MEDIA_ID.getValue(), id).toString();
+ assetFilter.setKSql(query);
+
+ ListResponse assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getAnonymousKs()))
+ .results;
+ assertThat(assetListResponse.getTotalCount()).isEqualTo(0);
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "try insert with empty isActive parameter")
+ public void insertEmptyIsActive() {
+ String ingestInsertXml = buildIngestVodXml(getVodData(MOVIE, INSERT), INSERT);
+ String invalidXml = ingestInsertXml.replaceAll("is_active=\"true\"", "is_active=\"\"");
+
+ Response resp = executeIngestVodRequest(invalidXml);
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath)).isEqualTo("media.IsActive cannot be empty");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "try insert with empty name")
+ public void insertWithEmptyName() {
+ // empty name value tag
+ VodData vodData = new VodData().mediaType(MOVIE).coguid(String.valueOf(getEpochInMillis())).name("");
+ String invalidXml = buildIngestVodXml(vodData, INSERT);
+
+ Response resp = executeIngestVodRequest(invalidXml);
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath)).isEqualTo("media.basic.name.value.text cannot be empty");
+
+ // empty name tag
+ VodData vodData1 = new VodData().mediaType(MOVIE).coguid(String.valueOf(getEpochInMillis()));
+ invalidXml = buildIngestVodXml(vodData1, INSERT);
+
+ resp = executeIngestVodRequest(invalidXml);
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath)).isEqualTo("media.basic.name cannot be empty");
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "try insert with invalid credentials")
+ public void insertWithInvalidCredentials() {
+ String statusMessage = "Invalid credentials";
+ String status = "ERROR";
+ String ingestInsertXml = buildIngestVodXml(new VodData(), INSERT);
+
+ // TODO: 9/17/2018 fix the test to support dynamic accounts
+
+ // invalid user name
+ String invalidXml = ingestInsertXml.replaceAll("Name>Test_API_27_03<", "Name>aTest_API_27_03<");
+ Response resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestStatusMessagePath)).isEqualTo(statusMessage);
+ assertThat(from(resp.asString()).getString(ingestStatusPath)).isEqualTo(status);
+
+ // invalid password
+ invalidXml = ingestInsertXml.replaceAll("passWord>Test_API_27_03<", "passWord>aTest_API_27_03<");
+ resp = executeIngestVodRequest(invalidXml);
+
+ assertThat(from(resp.asString()).getString(ingestStatusMessagePath)).isEqualTo(statusMessage);
+ assertThat(from(resp.asString()).getString(ingestStatusPath)).isEqualTo(status);
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "try insert with invalid meta or tag field")
+ public void insertWithInvalidMetaOrTagField() {
+ String suffix = "_" + getEpoch();
+ VodData vodData = getVodData(MOVIE, INSERT);
+
+ String updatedField = mediaNumberFieldName + suffix;
+ vodData.numbersMeta(Map.of(updatedField, getRandomDouble()));
+ assertInvalidMovieField(vodData, updatedField, "meta");
+ vodData.numbersMeta(Map.of());
+
+ updatedField = mediaBooleanFieldName + suffix;
+ vodData.booleansMeta(Map.of(updatedField, getRandomBoolean()));
+ assertInvalidMovieField(vodData, updatedField, "meta");
+ vodData.booleansMeta(Map.of());
+
+ updatedField = mediaTagFieldName + suffix;
+ vodData.tags(Map.of(updatedField, List.of(String.valueOf(getEpochInMillis()))));
+ assertInvalidMovieField(vodData, updatedField, "tag");
+ vodData.tags(Map.of());
+
+ updatedField = mediaTextFieldName + suffix;
+ vodData.stringsMeta(Map.of(updatedField, getRandomString()));
+ assertInvalidMovieField(vodData, updatedField, "meta");
+ vodData.stringsMeta(Map.of());
+
+ updatedField = mediaDateFieldName + suffix;
+ vodData.datesMeta(Map.of(updatedField, BaseUtils.getCurrentDateInFormat("yyyyMMddHHmmss")));
+ assertInvalidMovieField(vodData, updatedField, "meta");
+ vodData.datesMeta(Map.of());
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "insert multilingual fields", enabled = true)
+ public void insertMultiLingualFields() {
+ // TODO: 9/17/2018 complete test
+ // set multi languages
+ List languages = executor.executeSync(LanguageService.list(new LanguageFilter())
+ .setKs(getOperatorKs()))
+ .results
+ .getObjects();
+ String lang1 = languages.get(0).getCode();
+ String lang2 = languages.get(1).getCode();
+
+ // prepare data
+ String lang1Name = getRandomString();
+ String lang2Name = getRandomString();
+ String lang1Description = "description_" + lang1Name;
+ String lang2Description = "description_" + lang2Name;
+ String lang1Meta = "meta_" + lang1Name;
+ String lang2Meta = "meta_" + lang2Name;
+ String lang1Tag = "tag_" + lang1Name;
+ String lang2Tag = "tag_" + lang2Name;
+
+ // set strings meta
+ List metaNames = Arrays.asList("shmulik_str3", "BoxOffice", "alon_test2");
+ Map> metas = new HashMap<>();
+ metas.put(metaNames.get(0), Map.of(lang1, lang1Meta, lang2, lang2Meta));
+ metas.put(metaNames.get(1), Map.of(lang1, lang1Meta, lang2, lang2Meta));
+ metas.put(metaNames.get(2), Map.of(lang1, lang1Meta, lang2, lang2Meta));
+
+ // set tags
+ Map>> tags = new HashMap<>();
+ tags.put("Actors", Arrays.asList(Map.of(lang1, lang1Tag, lang2, lang2Tag), Map.of(lang1, lang1Tag, lang2, lang2Tag), Map.of(lang1, lang1Tag, lang2, lang2Tag)));
+ tags.put("TagsTest", Arrays.asList(Map.of(lang1, lang1Tag, lang2, lang2Tag), Map.of(lang1, lang1Tag, lang2, lang2Tag), Map.of(lang1, lang1Tag, lang2, lang2Tag)));
+
+ // ingest vod
+ VodData vodData = getVodData(MOVIE, INSERT)
+ .multilingualName(Map.of(lang1, lang1Name, lang2, lang2Name))
+ .multilingualDescription(Map.of(lang1, lang1Description, lang2, lang2Description))
+ .multilingualStringsMeta(metas)
+ .multilingualTags(tags);
+ MediaAsset asset = insertVod(vodData, false);
+
+ // assert multilingual data
+ // assert lang1 asset
+ Asset lang1Asset = executor.executeSync(get(String.valueOf(asset.getId()), AssetReferenceType.MEDIA)
+ .setKs(getAnonymousKs())
+ .setLanguage(lang1))
+ .results;
+
+ // assert name
+ assertThat(lang1Asset.getName()).isEqualTo(lang1Name);
+
+ // assert description
+ assertThat(lang1Asset.getDescription()).isEqualTo(lang1Description);
+
+ // aasert metas
+ assertThat(lang1Asset.getMetas().keySet()).containsAll(metaNames);
+ lang1Asset.getMetas().forEach((s, value) -> System.out.println(s + "_" + value.getDescription()));
+// assertThat(((MultilingualStringValue)asset.getMetas().get(mediaTextFieldName)).getValue())
+// .isEqualTo(stringMetaDataValue + JAP);
+
+ // assert tags
+// boolean isTagValueFound = isTagValueFound(tagValue1 + JAP, asset);
+// assertThat(isTagValueFound).isEqualTo(true);
+
+ // lang2
+ Asset lang2Asset = executor.executeSync(get(String.valueOf(asset.getId()), AssetReferenceType.MEDIA)
+ .setKs(getAnonymousKs())
+ .setLanguage(lang2))
+ .results;
+
+ assertThat(lang2Asset.getName()).isEqualTo(lang2Name);
+ assertThat(lang2Asset.getDescription()).isEqualTo(lang2Description);
+// assertThat(((MultilingualStringValue)asset.getMetas().get(mediaTextFieldName)).getValue()).isEqualTo(stringMetaDataValue);
+// // check tag value
+// isTagValueFound = isTagValueFound(tagValue1, asset);
+// assertThat(isTagValueFound).isEqualTo(true);
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "ingest VOD with empty images urls")
+ public void insertVodMediaBaseWithEmptyImageUrl() {
+ // empty thumb tag
+ VodData vodData = getVodData(MOVIE, INSERT).thumbUrl("");
+ String ingestXml = buildIngestVodXml(vodData, INSERT);
+
+ Response resp = executeIngestVodRequest(ingestXml);
+ assertThat(from(resp.asString()).getString(ingestAssetStatusWarningMessagePath)).contains("InvalidUrlForImageInvalidUrlForImage");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "ingest VOD files with same coguid")
+ public void insertVodMediaBaseFilesWithSameCoguid() {
+ // empty images tag
+ VodData vodData = getVodData(MOVIE, INSERT);
+ long epoch = getEpoch();
+ vodData.files().get(0).coguid(String.valueOf(epoch));
+ vodData.files().get(1).coguid(String.valueOf(epoch));
+ String ingestXml = buildIngestVodXml(vodData, INSERT);
+
+ Response resp = executeIngestVodRequest(ingestXml);
+ assertThat(from(resp.asString()).getString(ingestAssetStatusWarningMessagePath)).contains("MediaFileExternalIdMustBeUnique");
+ }
+
+ @Issue("BEO-5584")
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "ingest VOD with different Ppv", enabled = false)
+ public void updateVodMediaPpv() {
+ List ppvNames = DBUtils.getPpvNames(4);
+
+ // insert vod
+ List files = getDefaultAssetFiles(ppvNames.get(0), ppvNames.get(1));
+ VodData vodData = getVodData(MOVIE, INSERT).files(files);
+ MediaAsset movie = insertVod(vodData, true);
+
+ // update ppvs
+ files.get(0).ppvModule(ppvNames.get(2));
+ files.get(1).ppvModule(ppvNames.get(3));
+ vodData = new VodData().files(files);
+ movie = updateVod(movie.getExternalId(), vodData);
+
+ List mediaFiles = movie.getMediaFiles();
+ assertThat(mediaFiles.size()).isEqualTo(2);
+
+ // assert ppvs update
+ ProductPriceFilter filter = new ProductPriceFilter();
+ List fileIds = Arrays.asList(String.valueOf(mediaFiles.get(0).getId()), String.valueOf(mediaFiles.get(1).getId()));
+ filter.setFileIdIn(getConcatenatedString(fileIds));
+
+ com.kaltura.client.utils.response.base.Response> productPriceListResponse = executor.executeSync(ProductPriceService.list(filter).setKs(getAnonymousKs()));
+ PpvPrice ppvPrice1 = (PpvPrice) productPriceListResponse.results.getObjects().get(0);
+
+ String ppvName1 = executor.executeSync(PpvService.get(Long.parseLong(ppvPrice1
+ .getPpvModuleId()))
+ .setKs(getAnonymousKs()))
+ .results
+ .getName();
+
+ System.out.println(ppvName1);
+
+ // TODO: 9/17/2018 complete the test after the bug will be fixed
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "update VOD images")
+ public void updateImages() {
+ // insert vod
+ VodData vodData = getVodData(MOVIE, INSERT);
+ MediaAsset mediaAsset = insertVod(vodData, true);
+
+ // get list of original images
+ List originalImages = mediaAsset.getImages();
+ assertThat(originalImages.size()).isEqualTo(3);
+
+ // update vod images - enter 2 new images
+ List newRatios = Arrays.asList("2:1", "2:3");
+ String fakeImageUrl = "https://picsum.photos/200/300/?random";
+
+ VodData updateVodData = new VodData()
+ .thumbUrl(fakeImageUrl)
+ .thumbRatios(newRatios);
+ mediaAsset = updateVod(mediaAsset.getExternalId(), updateVodData);
+
+ // assert update
+ List images = mediaAsset.getImages();
+ assertThat(images.size()).isEqualTo(5);
+
+ List newImages = images.stream()
+ .filter(image -> originalImages.stream()
+ .map(MediaImage::getRatio)
+ .noneMatch(s1 -> s1.equals(image.getRatio())))
+ .collect(Collectors.toList());
+
+ newImages.forEach(image -> assertThat(image.getUrl()).isNotEmpty());
+ assertThat(newImages).extracting("ratio").containsExactlyInAnyOrderElementsOf(newRatios);
+ }
+
+ @Issue("BEO-5536")
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "update VOD files")
+ public void updateFiles() {
+ // insert vod
+ List fileTypeNames = DBUtils.getMediaFileTypeNames(2);
+ List ppvNames = DBUtils.getPpvNames(2);
+
+ VodData vodData = getVodData(MOVIE, INSERT);
+ List files = get2AssetFiles(fileTypeNames.get(0), fileTypeNames.get(1), ppvNames.get(0), ppvNames.get(1));
+ vodData.files(files);
+ MediaAsset mediaAsset = insertVod(vodData, true);
+
+ // update vod images
+ long e = getEpoch();
+ String r = String.valueOf(getRandomLong());
+
+ String coguid1 = "file_1_" + e + "_" + r;
+ String coguid2 = "file_2_" + e + "_" + r;
+
+ files.get(0).coguid(coguid1).assetDuration("5");
+ files.get(1).coguid(coguid2).assetDuration("5");
+
+ VodData updateVodData = new VodData()
+ .files(files);
+ List mediaFiles = updateVod(mediaAsset.getExternalId(), updateVodData).getMediaFiles();
+
+ // assert update
+ assertThat(mediaFiles.size()).isEqualTo(2);
+ mediaFiles.forEach(file -> assertThat(file.getDuration()).isEqualTo(5));
+ assertThat(mediaFiles).extracting("externalId").containsExactlyInAnyOrder(coguid1, coguid2);
+
+ // cleanup
+ deleteVod(mediaAsset.getExternalId());
+ }
+
+
+ // help methods
+ void assertInvalidMovieField(VodData vodData, String fieldName, String fieldType) {
+ Response resp = executeIngestVodRequest(buildIngestVodXml(vodData, INSERT));
+
+ assertThat(from(resp.asString()).getString(ingestAssetStatusMessagePath))
+ .isEqualTo(fieldType + ": " + fieldName + " does not exist for group");
+ }
+
+ void assertVodDeletion(String coguid) {
+ SearchAssetFilter assetFilter = new SearchAssetFilter();
+ assetFilter.setKSql(new KsqlBuilder().equal("externalId", coguid).toString());
+
+ com.kaltura.client.utils.response.base.Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getAnonymousKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+
+ deleteVod(coguid);
+
+ ListAssetBuilder listAssetBuilder = list(assetFilter).setKs(getAnonymousKs());
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> (executor.executeSync(listAssetBuilder).results.getTotalCount() == 0));
+ }
+
+ // to check that ingested file data are corresponding to getAsset file data
+ private void assertFiles(List ingestAssetFiles, String assetId) {
+ boolean isFileWasFound = false;
+
+ GetAssetBuilder assetBuilder = get(assetId, AssetReferenceType.MEDIA).setKs(getAnonymousKs());
+ com.kaltura.client.utils.response.base.Response assetGetResponse = executor.executeSync(assetBuilder);
+ List getMediaFiles = assetGetResponse.results.getMediaFiles();
+
+ for (VodFile ingestFile: ingestAssetFiles) {
+ for (MediaFile getFile: getMediaFiles) {
+ if (getFile.getType().equals(ingestFile.type())) {
+ isFileWasFound = true;
+ assertThat(getFile.getDuration().toString()).isEqualTo(ingestFile.assetDuration());
+ assertThat(getFile.getUrl()).isEqualTo(ingestFile.cdn_code());
+ assertThat(getFile.getAltStreamingCode()).isEqualTo(ingestFile.alt_cdn_code());
+ assertThat(getFile.getExternalStoreId()).isEqualTo(ingestFile.product_code());
+ assertThat(getFile.getExternalId()).isEqualTo(ingestFile.coguid());
+ }
+ }
+ }
+ assertThat(isFileWasFound).isEqualTo(true);
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/four_eight/PermissionsManagementTests.java b/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/four_eight/PermissionsManagementTests.java
new file mode 100644
index 000000000..e6b742035
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/featuresTests/versions/four_eight/PermissionsManagementTests.java
@@ -0,0 +1,497 @@
+package com.kaltura.client.test.tests.featuresTests.versions.four_eight;
+
+import com.kaltura.client.test.utils.BaseUtils;
+import com.kaltura.client.test.utils.PermissionManagementUtils;
+import com.kaltura.client.test.utils.dbUtils.PermissionsManagementDBUtils;
+import io.qameta.allure.Issue;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.apache.commons.io.FileUtils;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+import java.io.*;
+import java.util.List;
+import static com.kaltura.client.test.utils.BaseUtils.deleteFile;
+import static com.kaltura.client.test.utils.BaseUtils.getFileContent;
+import static com.kaltura.client.test.utils.PermissionManagementUtils.*;
+import static com.kaltura.client.test.utils.dbUtils.PermissionsManagementDBUtils.*;
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Class to test functionality described in https://kaltura.atlassian.net/browse/BEO-4885
+ * started in 4_8 and completed in 5_0_3
+ */
+@Test(groups = {"Permission management"})
+public class PermissionsManagementTests {
+
+ // these files added into project
+ String importOnly4TablesFilePath;
+ String path2EmptyFile;
+
+ @BeforeClass
+ public void setUp() {
+ ClassLoader classLoader = PermissionsManagementTests.class.getClassLoader();
+ File file = new File(classLoader.getResource("permission_management_data/empty_file.txt").getFile());
+ path2EmptyFile = file.getAbsolutePath();
+ file = new File(classLoader.getResource("permission_management_data/importOnly4Tables.txt").getFile());
+ importOnly4TablesFilePath = file.getAbsolutePath();
+ }
+
+ public static final String EXPORT_KEY = "e=";
+ public static final String IMPORT_KEY = "i=";
+ public static final String DELETE_KEY = "d=";
+ public static final String EXPORT_JSON_KEY = "n=";
+ public static final String IMPORT_JSON_KEY = "l=";
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "execute console util without parameters")
+ public void runningWithoutParameters() {
+ List commands = getConsoleCommand(fullPath2Util, "");
+ String consoleOutput = executeCommandsInConsole(commands);
+
+ assertThat(consoleOutput).contains("Permissions deployment tool");
+ assertThat(consoleOutput).contains("Shortcut: e");
+ assertThat(consoleOutput).contains("Shortcut: i");
+ assertThat(consoleOutput).contains("Shortcut: d");
+ assertThat(consoleOutput).contains("Shortcut: n");
+ assertThat(consoleOutput).contains("Shortcut: l");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Issue("BEO-5504")
+ @Test(description = "execute console util to export without mentioned file")
+ public void runningExportWithoutFile() {
+ List commands = getConsoleCommand(fullPath2Util, EXPORT_KEY);
+ String consoleOutput = executeCommandsInConsole(commands);
+
+ assertThat(consoleOutput).contains("The system cannot find the file specified");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Issue("BEO-5504")
+ @Test(description = "execute console util to import without mentioned file")
+ public void runningImportWithoutFile() {
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_KEY);
+ String consoleOutput = executeCommandsInConsole(commands);
+
+ assertThat(consoleOutput).contains("The system cannot find the file specified");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Issue("BEO-5504")
+ @Test(description = "execute console util to delete without mentioned file")
+ public void runningDeleteWithoutFile() {
+ List commands = getConsoleCommand(fullPath2Util, DELETE_KEY);
+ String consoleOutput = executeCommandsInConsole(commands);
+
+ assertThat(consoleOutput).contains("The system cannot find the file specified");
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "execute console util to export data from DB into file")
+ public void export() {
+ // prepare data inserting them in DB using stored procedures
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ String permissionItemName = "Asset_List_Max" + suffix;
+ PermissionManagementUtils.insertDataInAllTables(generatedDataFilePath, roleName, "partner*",
+ permissionItemName, "asset", "list", "permissionItemObject" + suffix,
+ "parameter" + suffix, false);
+
+ // export from DB
+ List commands = getConsoleCommand(fullPath2Util, EXPORT_KEY + dataFilePath);
+ executeCommandsInConsole(commands);
+
+ // checks that created file contains inserted data
+ String fileContent = getFileContent(dataFilePath);
+ assertThat(fileContent).contains(roleName);
+ assertThat(fileContent).contains(permissionItemName);
+ assertThat(fileContent).contains("permissionItemObject" + suffix);
+ assertThat(fileContent).contains("parameter" + suffix);
+
+ // cleaning
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+ PermissionsManagementDBUtils.deleteRoleAndItsPermissions(idRoleHavingName);
+ int idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName);
+ PermissionsManagementDBUtils.deletePermissionItem(idPermissionItemHavingName);
+ int idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName, 0);
+ PermissionsManagementDBUtils.deletePermission(idPermissionHavingName);
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "execute console util to import data into DB from file having only 4 tables instead of 5")
+ public void runningImportFromFileNotHavingAllTables() {
+ // remove log file
+ deleteFile(path2Log);
+
+ // try to import into DB
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_KEY + importOnly4TablesFilePath);
+ executeCommandsInConsole(commands);
+
+ String fileContent = getFileContent(path2Log);
+ assertThat(fileContent).contains("Import failed: reading from XML resulted in empty data set or data set with less than 5 tables");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "execute console util to try import data into DB from empty file")
+ public void runningImportFromEmptyFile() {
+ // remove log file
+ deleteFile(path2Log);
+
+ // try to import into DB
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_KEY + path2EmptyFile);
+ executeCommandsInConsole(commands);
+
+ String fileContent = getFileContent(path2Log);
+ assertThat(fileContent).contains("Failed importing permissions, ex = System.Xml.XmlException: Root element is missing");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Test(description = "execute console util to try delete data from DB using empty file")
+ public void runningDeleteUsingEmptyFile() {
+ // remove log file
+ deleteFile(path2Log);
+
+ // try to import into DB
+ List commands = getConsoleCommand(fullPath2Util, DELETE_KEY + path2EmptyFile);
+ executeCommandsInConsole(commands);
+
+ String fileContent = getFileContent(path2Log);
+ assertThat(fileContent).contains("Failed deleting permissions, ex = System.Xml.XmlException: Root element is missing");
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "execute console util to import data into DB from valid file")
+ public void importFromFile() {
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ String permissionItemName = "Asset_List_Max" + suffix;
+ PermissionManagementUtils.generateFileWithInsertedIntoDBData(generatedDataFilePath, roleName, "partner*",
+ permissionItemName, "asset", "list", "permissionItemObject" + suffix,
+ "parameter" + suffix, 1, 2, 3, 4, 5, false);
+
+ // import into DB
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_KEY + generatedDataFilePath);
+ executeCommandsInConsole(commands);
+
+ // check data in DB
+ int rowsInRolesHavingName = getCountRowsHavingRoleNameInRoles(roleName, 0);
+ assertThat(rowsInRolesHavingName).isEqualTo(1);
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+
+ int rowsInPermissionsHavingName = getCountRowsHavingRoleNameInPermissions(roleName, 0);
+ assertThat(rowsInPermissionsHavingName).isEqualTo(1);
+ int idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName, 0);
+
+ int idRolePermission = getCountSpecificRowsFromRolesPermissions(idRoleHavingName, idPermissionHavingName, 0);
+ assertThat(idRolePermission).isEqualTo(1);
+
+ int rowsInPermissionItemsHavingName = getCountRowsHavingNameInPermissionItems(permissionItemName);
+ assertThat(rowsInPermissionItemsHavingName).isEqualTo(1);
+ int idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName);
+
+ int rowsInPermissionsPermissions = getCountSpecificRowsFromPermissionsPermissionsItems(idPermissionHavingName,
+ idPermissionItemHavingName, 0);
+ assertThat(rowsInPermissionsPermissions).isEqualTo(1);
+
+ // cleaning
+ PermissionsManagementDBUtils.deleteRoleAndItsPermissions(idRoleHavingName);
+ PermissionsManagementDBUtils.deletePermissionItem(idPermissionItemHavingName);
+ PermissionsManagementDBUtils.deletePermission(idPermissionHavingName);
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "execute console util to check items from DB not mentioned in import file should be mentioned in log")
+ public void runningImportToCheckLogHasItemsFromDBNotMentionedInFile() {
+ // remove log file
+ deleteFile(path2Log);
+
+ // insert data in DB to check they will be mentioned in log file
+ String suffix1 = String.valueOf(BaseUtils.getEpoch()) + "inserted";
+ String roleName1 = "MaxTest" + suffix1;
+ String permissionItemName1 = "Asset_List_Max" + suffix1;
+ PermissionManagementUtils.insertDataInAllTables(generatedDataFilePath, roleName1, "partner*",
+ permissionItemName1, "asset", "list", "permissionItemObject" + suffix1,
+ "parameter" + suffix1, false);
+ String filePath2Check = generatedDataFilePath;
+
+ // generate import file data
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ String permissionItemName = "Asset_List_Max" + suffix;
+ PermissionManagementUtils.generateFileWithInsertedIntoDBData(generatedDataFilePath, roleName, "partner*",
+ permissionItemName, "asset", "list", "permissionItemObject" + suffix,
+ "parameter" + suffix, 1, 2, 3, 4, 5, false);
+
+ // import into DB
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_KEY + generatedDataFilePath);
+ executeCommandsInConsole(commands);
+
+ String fileContent = getFileContent(path2Log);
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName1, 0);
+ assertThat(fileContent).contains("!!NOT EXISTS IN SOURCE!! Table : role Id : " + idRoleHavingName + " Name : " + "MaxTest" + suffix1);
+
+ // cleaning
+ PermissionsManagementDBUtils.deleteRoleAndItsPermissions(idRoleHavingName);
+ int idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName1);
+ PermissionsManagementDBUtils.deletePermissionItem(idPermissionItemHavingName);
+ int idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName1, 0);
+ PermissionsManagementDBUtils.deletePermission(idPermissionHavingName);
+
+ idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+ PermissionsManagementDBUtils.deleteRoleAndItsPermissions(idRoleHavingName);
+ idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName);
+ PermissionsManagementDBUtils.deletePermissionItem(idPermissionItemHavingName);
+ idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName, 0);
+ PermissionsManagementDBUtils.deletePermission(idPermissionHavingName);
+
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "execute console util to delete data from DB")
+ public void deleteFromDB() {
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ String permissionItemName = "Asset_List_Max" + suffix;
+ PermissionManagementUtils.generateFileWithInsertedIntoDBData(generatedDataFilePath, roleName, "partner*",
+ permissionItemName, "asset", "list", "permissionItemObject" + suffix,
+ "parameter" + suffix, 1, 2, 3, 4, 5, false);
+
+ // import into DB
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_KEY + generatedDataFilePath);
+ executeCommandsInConsole(commands);
+
+ // check data in DB
+ int rowsInRolesHavingName = getCountRowsHavingRoleNameInRoles(roleName, 0);
+ assertThat(rowsInRolesHavingName).isEqualTo(1);
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+
+ int rowsInPermissionsHavingName = getCountRowsHavingRoleNameInPermissions(roleName, 0);
+ assertThat(rowsInPermissionsHavingName).isEqualTo(1);
+ int idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName, 0);
+
+ int idRolePermission = getCountSpecificRowsFromRolesPermissions(idRoleHavingName, idPermissionHavingName, 0);
+ assertThat(idRolePermission).isEqualTo(1);
+
+ int rowsInPermissionItemsHavingName = getCountRowsHavingNameInPermissionItems(permissionItemName);
+ assertThat(rowsInPermissionItemsHavingName).isEqualTo(1);
+ int idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName);
+
+ int rowsInPermissionsPermissions = getCountSpecificRowsFromPermissionsPermissionsItems(idPermissionHavingName,
+ idPermissionItemHavingName, 0);
+ assertThat(rowsInPermissionsPermissions).isEqualTo(1);
+
+ // remove log file
+ deleteFile(path2Log);
+
+ // delete from DB
+ commands = getConsoleCommand(fullPath2Util, DELETE_KEY + generatedDataFilePath);
+ executeCommandsInConsole(commands);
+
+ // DB should be empty
+ rowsInRolesHavingName = getCountRowsHavingRoleNameInRoles(roleName, 0);
+ assertThat(rowsInRolesHavingName).isEqualTo(0);
+
+ rowsInPermissionsHavingName = getCountRowsHavingRoleNameInPermissions(roleName, 0);
+ assertThat(rowsInPermissionsHavingName).isEqualTo(0);
+
+ rowsInPermissionItemsHavingName = getCountRowsHavingNameInPermissionItems(permissionItemName + suffix);
+ assertThat(rowsInPermissionItemsHavingName).isEqualTo(0);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "execute console util to import already existed data into DB from valid file")
+ public void importAlreadyExistedFromFile() {
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ String permissionItemName = "Asset_List_Max" + suffix;
+ PermissionManagementUtils.generateFileWithInsertedIntoDBData(generatedDataFilePath, roleName, "partner*",
+ permissionItemName, "asset", "list", "permissionItemObject" + suffix,
+ "parameter" + suffix, 1, 2, 3, 4, 5, false);
+
+ // import into DB
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_KEY + generatedDataFilePath);
+ executeCommandsInConsole(commands);
+
+ // retry import
+ executeCommandsInConsole(commands);
+
+ // check data in DB
+ int rowsInRolesHavingName = getCountRowsHavingRoleNameInRoles(roleName, 0);
+ assertThat(rowsInRolesHavingName).isEqualTo(1);
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+
+ int rowsInPermissionsHavingName = getCountRowsHavingRoleNameInPermissions(roleName, 0);
+ assertThat(rowsInPermissionsHavingName).isEqualTo(1);
+ int idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName, 0);
+
+ int idRolePermission = getCountSpecificRowsFromRolesPermissions(idRoleHavingName, idPermissionHavingName, 0);
+ assertThat(idRolePermission).isEqualTo(1);
+
+ int rowsInPermissionItemsHavingName = getCountRowsHavingNameInPermissionItems(permissionItemName);
+ assertThat(rowsInPermissionItemsHavingName).isEqualTo(1);
+ int idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName);
+
+ int rowsInPermissionsPermissions = getCountSpecificRowsFromPermissionsPermissionsItems(idPermissionHavingName,
+ idPermissionItemHavingName, 0);
+ assertThat(rowsInPermissionsPermissions).isEqualTo(1);
+
+ // cleaning
+ PermissionsManagementDBUtils.deleteRoleAndItsPermissions(idRoleHavingName);
+ PermissionsManagementDBUtils.deletePermissionItem(idPermissionItemHavingName);
+ PermissionsManagementDBUtils.deletePermission(idPermissionHavingName);
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "execute console util to try delete data in DB using file with invalid tags")
+ public void runningDeleteUsingFileWithInvalidTags() {
+ // insert role in DB
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ PermissionsManagementDBUtils.insertRole(roleName);
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles("MaxTest" + suffix, 0);
+
+ PermissionManagementUtils.generateFileWithInvalidTagForRole(generatedDataFilePath, roleName, idRoleHavingName);
+
+ // try delete
+ List commands = getConsoleCommand(fullPath2Util, DELETE_KEY + generatedDataFilePath);
+ executeCommandsInConsole(commands);
+
+ // check data still in DB
+ int rowsInRolesHavingName = getCountRowsHavingRoleNameInRoles(roleName, 0);
+ assertThat(rowsInRolesHavingName).isEqualTo(1);
+ }
+
+ @Severity(SeverityLevel.NORMAL)
+ @Test(description = "execute console util to delete data in 1 related table of DB")
+ public void deleteOnlyFromOneTable() {
+ // insert role in DB
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ PermissionsManagementDBUtils.insertRole(roleName);
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+
+ PermissionManagementUtils.generateFileForRole(generatedDataFilePath, roleName, idRoleHavingName);
+
+ // delete
+ List commands = getConsoleCommand(fullPath2Util, DELETE_KEY + generatedDataFilePath);
+ executeCommandsInConsole(commands);
+
+ // check data deleted from DB
+ int rowsInRolesHavingName = getCountRowsHavingRoleNameInRoles(roleName, 0);
+ assertThat(rowsInRolesHavingName).isEqualTo(0);
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Issue("BEO-5504")
+ @Test(description = "execute console util to export in JSON without mentioned file")
+ public void runningExportJsonWithoutFile() {
+ List commands = getConsoleCommand(fullPath2Util, EXPORT_JSON_KEY);
+ String consoleOutput = executeCommandsInConsole(commands);
+
+ assertThat(consoleOutput).contains("The system cannot find the file specified");
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Issue("BEO-5504")
+ @Test(description = "execute console util to import in JSON without mentioned file")
+ public void runningImportJsonWithoutFile() {
+ List commands = getConsoleCommand(fullPath2Util, IMPORT_JSON_KEY);
+ String consoleOutput = executeCommandsInConsole(commands);
+
+ assertThat(consoleOutput).contains("The system cannot find the file specified");
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "execute console util to export in JSON from DB")
+ public void exportJson() throws IOException {
+ // clean folder with logs
+ FileUtils.cleanDirectory(new File(path2JsonFolder));
+
+ // prepare data inserting them in DB using stored procedures
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ String permissionItemName = "Asset_List_Max" + suffix;
+ String serviceName = "asset";
+ PermissionManagementUtils.insertDataInAllTables(generatedDataFilePath, roleName, "partner*",
+ permissionItemName, serviceName, "list", "permissionItemObject" + suffix,
+ "parameter" + suffix, true);
+ // command
+ List commands = getConsoleCommand(fullPath2Util, EXPORT_JSON_KEY + path2JsonFolder);
+ executeCommandsInConsole(commands);
+
+ String importFileContent = getFileContent(generatedDataFilePath);
+ assertThat(importFileContent).contains(roleName);
+ assertThat(importFileContent).contains(permissionItemName);
+ checkActionResult(serviceName, importFileContent);
+
+ // cleaning
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+ PermissionsManagementDBUtils.deleteRoleAndItsPermissions(idRoleHavingName);
+ int idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName);
+ PermissionsManagementDBUtils.deletePermissionItem(idPermissionItemHavingName);
+ int idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName, 0);
+ PermissionsManagementDBUtils.deletePermission(idPermissionHavingName);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Test(description = "execute console util to import from JSON into DB")
+ public void importJson() throws IOException {
+ // clean folder with logs
+ FileUtils.cleanDirectory(new File(path2JsonFolder));
+
+ // export command to get results and not break the system
+ List commands = getConsoleCommand(fullPath2Util, EXPORT_JSON_KEY + path2JsonFolder);
+ executeCommandsInConsole(commands);
+
+ // prepare data
+ String suffix = String.valueOf(BaseUtils.getEpoch());
+ String roleName = "MaxTest" + suffix;
+ String permissionItemName = "Asset_List_Max" + suffix;
+ String serviceName = "asset";
+ PermissionManagementUtils.fillFilesWithImportData(roleName, permissionItemName, "partner*", serviceName, "list");
+
+ // import command
+ commands = getConsoleCommand(fullPath2Util, IMPORT_JSON_KEY + path2JsonFolder);
+ executeCommandsInConsole(commands);
+
+ // find new records in DB after the import
+ int idRoleHavingName = getIdRecordHavingRoleNameInRoles(roleName, 0);
+ int idPermissionItemHavingName = getIdRecordHavingNameInPermissionItems(permissionItemName);
+ int idPermissionHavingName = getIdRecordHavingRoleNameInPermissions(roleName, 0);
+ assertThat(idRoleHavingName).isGreaterThan(0);
+ assertThat(idPermissionItemHavingName).isGreaterThan(0);
+ assertThat(idPermissionHavingName).isGreaterThan(0);
+
+ // cleaning
+ PermissionsManagementDBUtils.deleteRoleAndItsPermissions(idRoleHavingName);
+ PermissionsManagementDBUtils.deletePermissionItem(idPermissionItemHavingName);
+ PermissionsManagementDBUtils.deletePermission(idPermissionHavingName);
+ }
+
+ // method checks that all related files contain information related to service
+ /**
+ *
+ * @param serviceName - name of service (e.g.: "asset")
+ * @param importFileContent - file created during adding data into DB by util PermissionManagementUtils.insertDataInAllTables
+ * data in that file related to data from files with roles info, permissions info and methods info and separated by symbol ";"
+ */
+ void checkActionResult(String serviceName, String importFileContent) {
+ // data prepared so that they splitted by symbol ";"
+ String[] results = importFileContent.split(";");
+ String contentOfJsonFile = getFileContent(path2JsonRoles)
+ .replaceAll(" ", "");
+ //.replaceAll("\\t", "");
+ assertThat(contentOfJsonFile).contains(results[0]
+ .replaceAll(" ", ""));
+ contentOfJsonFile = getFileContent(path2JsonPermissions)
+ .replaceAll(" ", "");
+ //.replaceAll("\\t", "");
+ assertThat(contentOfJsonFile).contains(results[1]
+ .replaceAll(" ", ""));
+ contentOfJsonFile = getFileContent(path2JsonMethods + serviceName + ".json")
+ .replaceAll(" ", "");
+ //.replaceAll("\\t", "");
+ assertThat(contentOfJsonFile).contains(results[2].replaceAll(" ", ""));
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetHistoryTests/AssetHistoryActionCleanLists.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetHistoryTests/AssetHistoryActionCleanLists.java
deleted file mode 100644
index eda434237..000000000
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetHistoryTests/AssetHistoryActionCleanLists.java
+++ /dev/null
@@ -1,205 +0,0 @@
-package com.kaltura.client.test.tests.servicesTests.AssetHistoryTests;
-
-import com.kaltura.client.enums.BookmarkActionType;
-import com.kaltura.client.enums.WatchStatus;
-import com.kaltura.client.services.AssetHistoryService;
-import com.kaltura.client.test.tests.BaseTest;
-import com.kaltura.client.test.utils.AssetHistoryUtils;
-import com.kaltura.client.types.AssetHistory;
-import com.kaltura.client.types.AssetHistoryFilter;
-import com.kaltura.client.types.Household;
-import com.kaltura.client.types.ListResponse;
-import com.kaltura.client.utils.response.base.Response;
-import io.qameta.allure.Description;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.Test;
-
-import static com.kaltura.client.services.AssetHistoryService.CleanAssetHistoryBuilder;
-import static com.kaltura.client.services.AssetHistoryService.ListAssetHistoryBuilder;
-import static com.kaltura.client.test.IngestConstants.EPISODE_MEDIA_TYPE;
-import static com.kaltura.client.test.IngestConstants.MOVIE_MEDIA_TYPE;
-import static com.kaltura.client.test.Properties.EPISODE_MEDIA_TYPE_ID;
-import static com.kaltura.client.test.Properties.getProperty;
-import static com.kaltura.client.test.utils.HouseholdUtils.createHousehold;
-import static com.kaltura.client.test.utils.HouseholdUtils.getHouseholdMasterUserKs;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class AssetHistoryActionCleanLists extends BaseTest {
-
- private final int position1 = 10;
- private final int position2 = 20;
- private final int numbOfDevices = 1;
- private final int numOfUsers = 1;
-
-
- @BeforeClass
- // TODO: 5/3/2018 change before method name
- private void add_tests_before_class() {
-
- }
-
- @Description("/assetHistory/action/clean - no filtering")
- @Test
- private void cleanHistory() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String masterUserKs = getHouseholdMasterUserKs(household, null);
- String userKs = getHouseholdMasterUserKs(household, null);
-
- // Ingest and bookmark first asset
- AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, position1, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset
- AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, position2, BookmarkActionType.FIRST_PLAY);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL, null);
-
- //assetHistory/action/list - both assets should returned
- ListAssetHistoryBuilder listAssetHistoryBuilder = AssetHistoryService.list(assetHistoryFilter, null)
- .setKs(masterUserKs);
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(2);
-
- //assetHistory/action/clean
- CleanAssetHistoryBuilder cleanAssetHistoryBuilder = AssetHistoryService.clean(assetHistoryFilter);
- cleanAssetHistoryBuilder.setKs(masterUserKs);
- executor.executeSync(cleanAssetHistoryBuilder);
-
- // assetHistory/action/list - after clean - no object returned
- listAssetHistoryBuilder = AssetHistoryService.list(assetHistoryFilter, null)
- .setKs(masterUserKs);
- assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(0);
- }
-
- @Description("/assetHistory/action/clean - filtered by asset id")
- @Test
- private void cleanSpecifcAssetHistory() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String masterUserKs = getHouseholdMasterUserKs(household, null);
- String userKs = getHouseholdMasterUserKs(household, null);
-
- // Ingest and bookmark first asset
- Long assetId1 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, position1, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset
- Long assetId2 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, position2, BookmarkActionType.FIRST_PLAY);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(String.valueOf(assetId1), null, WatchStatus.ALL, null);
-
- //assetHistory/action/clean
- CleanAssetHistoryBuilder cleanAssetHistoryBuilder = AssetHistoryService.clean(assetHistoryFilter);
- cleanAssetHistoryBuilder.setKs(masterUserKs);
- executor.executeSync(cleanAssetHistoryBuilder);
-
- // Update assetHistoryFilter object (assetIdIn = null)
- assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL, null);
-
- // assetHistory/action/list - after clean - only asset id 2 returned (was not cleaned)
- ListAssetHistoryBuilder listAssetHistoryBuilder = AssetHistoryService.list(assetHistoryFilter, null);
- listAssetHistoryBuilder.setKs(masterUserKs);
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetId2);
- }
-
- @Description("/assetHistory/action/clean - filtered by asset type")
- @Test
- private void cleanSpecifcAssetTypeHistory() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String masterUserKs = getHouseholdMasterUserKs(household, null);
- String userKs = getHouseholdMasterUserKs(household, null);
-
- // Ingest and bookmark first asset
- Long assetId1 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, position1, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset
- Long assetId2 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, EPISODE_MEDIA_TYPE, position2, BookmarkActionType.FIRST_PLAY);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL, getProperty(EPISODE_MEDIA_TYPE_ID));
-
- //assetHistory/action/clean - only episode type (asset id 2)
-
- CleanAssetHistoryBuilder cleanAssetHistoryBuilder = AssetHistoryService.clean(assetHistoryFilter);
- cleanAssetHistoryBuilder.setKs(masterUserKs);
- executor.executeSync(cleanAssetHistoryBuilder);
-
- // Update assetHistoryFilter object (assetIdIn = null)
- assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL, null);
-
- // assetHistory/action/list - after clean - only asset id 1 returned (was not cleaned)
-
- ListAssetHistoryBuilder listAssetHistoryBuilder = AssetHistoryService.list(assetHistoryFilter, null);
- listAssetHistoryBuilder.setKs(masterUserKs);
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetId1);
- }
-
- @Description("/assetHistory/action/clean - filtered by asset progress")
- @Test
- private void cleanAssetsAccordingToWatchStatusDone() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String masterUserKs = getHouseholdMasterUserKs(household, null);
- String userKs = getHouseholdMasterUserKs(household, null);
-
- // Ingest and bookmark first asset
- Long assetId1 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, position1, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset
- Long assetId2 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, EPISODE_MEDIA_TYPE, position2, BookmarkActionType.FINISH);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.DONE, null);
-
- //assetHistory/action/clean - only asset that were finished (asset 2)
-
- CleanAssetHistoryBuilder cleanAssetHistoryBuilder = AssetHistoryService.clean(assetHistoryFilter);
- cleanAssetHistoryBuilder.setKs(masterUserKs);
- executor.executeSync(cleanAssetHistoryBuilder);
-
- assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL, null);
-
- // assetHistory/action/list - after clean - only asset id 1 returned (was not cleaned)
-
- ListAssetHistoryBuilder listAssetHistoryBuilder = AssetHistoryService.list(assetHistoryFilter, null);
- listAssetHistoryBuilder.setKs(masterUserKs);
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetId1);
- }
-
- @Description("/assetHistory/action/clean - filtered by asset progress")
- @Test
- private void cleanAssetsAccordingToWatchStatusProgress() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String masterUserKs = getHouseholdMasterUserKs(household, null);
- String userKs = getHouseholdMasterUserKs(household, null);
-
- // Ingest and bookmark first asset
- Long assetId1 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, position1, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset
- Long assetId2 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, EPISODE_MEDIA_TYPE, position2, BookmarkActionType.FINISH);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.PROGRESS, null);
-
- //assetHistory/action/clean - only asset that in progress (asset 1)
- CleanAssetHistoryBuilder cleanAssetHistoryBuilder = AssetHistoryService.clean(assetHistoryFilter);
- cleanAssetHistoryBuilder.setKs(masterUserKs);
- executor.executeSync(cleanAssetHistoryBuilder);
-
- assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL, null);
-
- // assetHistory/action/list - after clean - only asset id 2 returned (was not cleaned)
- ListAssetHistoryBuilder listAssetHistoryBuilder = AssetHistoryService.list(assetHistoryFilter, null);
- listAssetHistoryBuilder.setKs(masterUserKs);
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetId2);
- }
-}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetHistoryTests/AssetHistoryListTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetHistoryTests/AssetHistoryListTests.java
deleted file mode 100644
index 4d172a71f..000000000
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetHistoryTests/AssetHistoryListTests.java
+++ /dev/null
@@ -1,206 +0,0 @@
-package com.kaltura.client.test.tests.servicesTests.AssetHistoryTests;
-
-import com.kaltura.client.enums.AssetType;
-import com.kaltura.client.enums.BookmarkActionType;
-import com.kaltura.client.enums.WatchStatus;
-import com.kaltura.client.test.tests.BaseTest;
-import com.kaltura.client.test.utils.AssetHistoryUtils;
-import com.kaltura.client.types.AssetHistory;
-import com.kaltura.client.types.AssetHistoryFilter;
-import com.kaltura.client.types.Household;
-import com.kaltura.client.types.ListResponse;
-import com.kaltura.client.utils.response.base.Response;
-import io.qameta.allure.Description;
-import org.testng.annotations.Test;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import static com.kaltura.client.services.AssetHistoryService.*;
-import static com.kaltura.client.test.IngestConstants.EPISODE_MEDIA_TYPE;
-import static com.kaltura.client.test.IngestConstants.MOVIE_MEDIA_TYPE;
-import static com.kaltura.client.test.Properties.MOVIE_MEDIA_TYPE_ID;
-import static com.kaltura.client.test.Properties.getProperty;
-import static com.kaltura.client.test.utils.BaseUtils.getConcatenatedString;
-import static com.kaltura.client.test.utils.BaseUtils.getTimeInEpoch;
-import static com.kaltura.client.test.utils.HouseholdUtils.createHousehold;
-import static com.kaltura.client.test.utils.HouseholdUtils.getHouseholdMasterUserKs;
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class AssetHistoryListTests extends BaseTest {
-
- private final int position1 = 10;
- private final int position2 = 20;
- private final int numbOfDevices = 1;
- private final int numOfUsers = 1;
-
-
- @Description("/AssetHistory/action/list - with no filter")
- @Test
- private void vodAssetHistory() {
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String masterUserKs = getHouseholdMasterUserKs(household, null);
-
- // Ingest and bookmark first asset
- Long assetId1 = AssetHistoryUtils.ingestAssetAndPerformBookmark(masterUserKs, MOVIE_MEDIA_TYPE, position1, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset
- Long assetId2 = AssetHistoryUtils.ingestAssetAndPerformBookmark(masterUserKs, MOVIE_MEDIA_TYPE, position2, BookmarkActionType.FIRST_PLAY);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL, null);
-
- //assetHistory/action/list - both assets should returned
- ListAssetHistoryBuilder listAssetHistoryBuilder = list(assetHistoryFilter, null)
- .setKs(masterUserKs);
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- // First object
- AssetHistory assetHistoryObject1 = assetHistoryListResponse.results.getObjects().get(0);
- // Second object
- AssetHistory assetHistoryObject2 = assetHistoryListResponse.results.getObjects().get(1);
-
- // Assertions for first object returned
- assertThat(assetHistoryObject1.getAssetId()).isEqualTo(assetId2);
- assertThat(assetHistoryObject1.getAssetType()).isEqualTo(AssetType.MEDIA);
- assertThat(assetHistoryObject1.getPosition()).isEqualTo(position2);
- assertThat(assetHistoryObject1.getDuration()).isGreaterThan(0);
-
- // Verify that flag is set to false (user hasn't finish watching the asset)
- assertThat(assetHistoryObject1.getFinishedWatching()).isFalse();
- assertThat(assetHistoryObject1.getWatchedDate()).isLessThanOrEqualTo(getTimeInEpoch(0));
-
- // Assertions for second object returned
- assertThat(assetHistoryObject2.getAssetId()).isEqualTo(assetId1);
- assertThat(assetHistoryObject2.getAssetType()).isEqualTo(AssetType.MEDIA);
- assertThat(assetHistoryObject2.getPosition()).isEqualTo(position1);
-
- // Assert total count = 2 (two bookmarks)
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(2);
-
- // clean
- clean_asset_history(assetHistoryFilter, household);
- }
-
- @Description("/AssetHistory/action/list -filtered by movie asset id")
- @Test
- private void vodAssetHistoryFilteredByAssetId() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String masterUserKs = getHouseholdMasterUserKs(household, null);
-
- List assetIds = new ArrayList<>();
- int numOfBookmarks = 3;
- for (int i = 0; i < numOfBookmarks; i++) {
- long assetId = AssetHistoryUtils.ingestAssetAndPerformBookmark(masterUserKs, MOVIE_MEDIA_TYPE, position1, BookmarkActionType.FIRST_PLAY);
- assetIds.add(assetId);
- }
-
- // Ingest and bookmark first asset
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(String.valueOf(assetIds.get(1)), null, WatchStatus.ALL, null);
-
- //assetHistory/action/list - filter by asset 2 id
- ListAssetHistoryBuilder listAssetHistoryBuilder = list(assetHistoryFilter, null)
- .setKs(masterUserKs);
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetIds.get(1));
-
- String concatenatedString = getConcatenatedString(String.valueOf(assetIds.get(1)), String.valueOf(assetIds.get(2)));
-
- //assetHistory/action/list - filter by asset 2 and asset 3 ids
- assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(concatenatedString, null, WatchStatus.ALL, null);
-
- listAssetHistoryBuilder = list(assetHistoryFilter, null)
- .setKs(masterUserKs);
- assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- List assetHistoryList = assetHistoryListResponse.results.getObjects();
- assertThat(assetHistoryList);
-
- List assetHistoryIdsList = new ArrayList<>();
- for (AssetHistory assetHistory : assetHistoryList) {
- assetHistoryIdsList.add(assetHistory.getAssetId());
- }
- assertThat(assetHistoryIdsList).containsOnly(assetIds.get(1), assetIds.get(2));
-
- // clean
- clean_asset_history(assetHistoryFilter, household);
- }
-
- @Description("/AssetHistory/action/list -filtered by movie type id")
- @Test
- private void vodAssetHistoryFilteredByAssetType() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String userKs = getHouseholdMasterUserKs(household, null);
-
-
- // Ingest and bookmark first asset (movie in first play)
- Long assetId1 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, 10, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset (movie in finish action)
- Long assetId2 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, EPISODE_MEDIA_TYPE, 10, BookmarkActionType.FIRST_PLAY);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.ALL,
- getProperty(MOVIE_MEDIA_TYPE_ID));
-
- //assetHistory/action/list - filter by in progress assets only
-
- ListAssetHistoryBuilder listAssetHistoryBuilder = list(assetHistoryFilter, null);
- listAssetHistoryBuilder.setKs(getHouseholdMasterUserKs(household, null));
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetId1);
-
- // clean
- clean_asset_history(assetHistoryFilter, household);
- }
-
-
- @Description("/AssetHistory/action/list -filtered by assets progress")
- @Test
- private void vodAssetHistoryFilteredByAssetProgress() {
-
- Household household = createHousehold(numOfUsers, numbOfDevices, false);
- String userKs = getHouseholdMasterUserKs(household, null);
-
-
- // Ingest and bookmark first asset (movie in first play)
- Long assetId1 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, MOVIE_MEDIA_TYPE, 10, BookmarkActionType.FIRST_PLAY);
- // Ingest and bookmark second asset (movie in finish action)
- Long assetId2 = AssetHistoryUtils.ingestAssetAndPerformBookmark(userKs, EPISODE_MEDIA_TYPE, 100, BookmarkActionType.FINISH);
-
- AssetHistoryFilter assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.PROGRESS, null);
-
- //assetHistory/action/list - filter by in progress assets only
-
- ListAssetHistoryBuilder listAssetHistoryBuilder = list(assetHistoryFilter, null);
- listAssetHistoryBuilder.setKs(getHouseholdMasterUserKs(household, null));
- Response> assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetId1);
-
- assetHistoryFilter = AssetHistoryUtils.getAssetHistoryFilter(null, null, WatchStatus.DONE, null);
-
- //assetHistory/action/list - filter by finished assets only
-
- listAssetHistoryBuilder = list(assetHistoryFilter, null);
- assetHistoryListResponse = executor.executeSync(listAssetHistoryBuilder);
-
- assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
- assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(assetId2);
-
- // clean
- clean_asset_history(assetHistoryFilter, household);
- }
-
-
- private void clean_asset_history(AssetHistoryFilter assetHistoryFilter, Household household) {
- CleanAssetHistoryBuilder cleanAssetHistoryBuilder = clean(assetHistoryFilter);
- cleanAssetHistoryBuilder.setKs(getHouseholdMasterUserKs(household, null));
- executor.executeSync(cleanAssetHistoryBuilder);
- }
-
- //todo - Currently EPG program not returned in response (Ticket was opened to Omer - BEO-4594]
-}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetCountTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetCountTests.java
new file mode 100644
index 000000000..4e6239b88
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetCountTests.java
@@ -0,0 +1,293 @@
+package com.kaltura.client.test.tests.servicesTests.AssetTests;
+import com.kaltura.client.services.AssetService;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.MediaType;
+import com.kaltura.client.test.utils.KsqlBuilder;
+
+import com.kaltura.client.test.utils.dbUtils.DBUtils;
+import com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils;
+import com.kaltura.client.types.*;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+
+
+import static com.kaltura.client.services.AssetService.*;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getMediaTypeId;
+import static com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils.*;
+import static com.kaltura.client.test.tests.enums.KsqlKey.EPG_ID;
+import static com.kaltura.client.test.tests.enums.KsqlKey.MEDIA_ID;
+import static com.kaltura.client.test.tests.enums.MediaType.MOVIE;
+import static com.kaltura.client.test.utils.BaseUtils.getRandomValue;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.*;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.insertVod;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class AssetCountTests extends BaseTest {
+
+ private ProgramAsset program, program2;
+ private MediaAsset asset, asset2;
+
+ //TODO - Change all hardcoded values after Alon will add DB meta anf tags utils.
+
+ private final String metaName1 = "synopsis";
+ private final String metaValue1 = metaName1 + getRandomValue("_");
+
+ private final String metaName2 = "runtime";
+ private final String metaValue2 = metaName2 + getRandomValue("_");
+ private final String metaValue3 = metaName2 + getRandomValue("_");
+
+ private final String tagName = "Studio";
+ private final String tagValue = tagName + getRandomValue("_");
+
+ private final String epgMetaName = "Country";
+ private final String epgMetaValue = epgMetaName + getRandomValue("_");
+
+ private final String sharedTagName = "Director";
+ private final String sharedTagValue = sharedTagName + getRandomValue("_");
+
+ @BeforeClass
+ private void asset_count_before_class() {
+
+ // Metas
+ HashMap stringMetaMap = new HashMap<>();
+ stringMetaMap.put(metaName1, metaValue1);
+ stringMetaMap.put(metaName2,metaValue2);
+
+ // Tags
+ HashMap> stringTagMap = new HashMap<>();
+ stringTagMap.put(sharedTagName, Arrays.asList(sharedTagValue));
+ stringTagMap.put(tagName,Arrays.asList(tagValue));
+
+ // ingest asset 1
+ VodData vodData1 = new VodData()
+ .mediaType(MOVIE)
+ .stringsMeta(stringMetaMap)
+ .tags(stringTagMap);
+ asset = insertVod(vodData1, true);
+
+ HashMap stringMetaMap2 = new HashMap<>();
+ stringMetaMap2.put(metaName1, metaValue1);
+ stringMetaMap2.put(metaName2,metaValue3);
+ stringTagMap.put(tagName,Arrays.asList(tagValue));
+
+ // ingest asset 2
+ VodData vodData2 = new VodData()
+ .mediaType(MOVIE)
+ .stringsMeta(stringMetaMap2);
+ asset2 = insertVod(vodData2, true);
+
+ HashMap epgMetas = new HashMap<>();
+ epgMetas.put(epgMetaName, epgMetaValue);
+
+ HashMap epgTags = new HashMap<>();
+ epgTags.put(sharedTagName, sharedTagValue);
+
+ // ingest epg programs
+ EpgData epgData = new EpgData(getSharedEpgChannelName());
+ epgData.seasonsNum(1);
+ epgData.episodesNum(2);
+ epgData.metas(epgMetas);
+ epgData.tags(epgTags);
+
+ List programsList = IngestEpgUtils.insertEpg(epgData);
+ program = programsList.get(0);
+ program2 = programsList.get(1);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("2 VOD assets with the same meta (synopsis) value and pass the meta name in the count request")
+ @Test
+ private void groupByVodMeta() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .closeOr()
+ .toString();
+
+ SearchAssetFilter searchAssetFilter = new SearchAssetFilter();
+ searchAssetFilter.setKSql(query);
+ searchAssetFilter.setTypeIn(String.valueOf(DBUtils.getMediaTypeId(MediaType.MOVIE)));
+
+ ArrayList arrayList = new ArrayList<>();
+ AssetMetaOrTagGroupBy assetMetaOrTagGroupBy = new AssetMetaOrTagGroupBy();
+ assetMetaOrTagGroupBy.setValue(metaName1);
+ arrayList.add(assetMetaOrTagGroupBy);
+
+ searchAssetFilter.setGroupBy(arrayList);
+ AssetService.CountAssetBuilder countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+
+ // asset/action/count - 2 VOD assets in count
+ Response assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(2);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("2 VOD assets with the same tag (Genre) value and pass the tag name in the count request")
+ @Test
+ private void groupByVodTag() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .closeOr()
+ .toString();
+
+ SearchAssetFilter searchAssetFilter = new SearchAssetFilter();
+ searchAssetFilter.setKSql(query);
+ searchAssetFilter.setTypeIn(String.valueOf(DBUtils.getMediaTypeId(MediaType.MOVIE)));
+
+ ArrayList arrayList = new ArrayList<>();
+ AssetMetaOrTagGroupBy assetMetaOrTagGroupBy = new AssetMetaOrTagGroupBy();
+ assetMetaOrTagGroupBy.setValue(tagName);
+ arrayList.add(assetMetaOrTagGroupBy);
+
+ searchAssetFilter.setGroupBy(arrayList);
+ AssetService.CountAssetBuilder countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+
+ // asset/action/count - 2 VOD assets in count
+ Response assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(2);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("2 VOD assets with different meta (Runtime) value and pass the meta name in the count request")
+ @Test
+ private void groupByVodMetaWithDifferentValues() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .closeOr()
+ .toString();
+
+ SearchAssetFilter searchAssetFilter = new SearchAssetFilter();
+ searchAssetFilter.setKSql(query);
+ searchAssetFilter.setTypeIn(String.valueOf(DBUtils.getMediaTypeId(MediaType.MOVIE)));
+
+ ArrayList arrayList = new ArrayList<>();
+ AssetMetaOrTagGroupBy assetMetaOrTagGroupBy = new AssetMetaOrTagGroupBy();
+ assetMetaOrTagGroupBy.setValue(metaName2);
+ arrayList.add(assetMetaOrTagGroupBy);
+
+ searchAssetFilter.setGroupBy(arrayList);
+ AssetService.CountAssetBuilder countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+
+ // asset/action/count - 2 VOD assets in count
+ Response assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(2);
+ assertThat(assetCountResponse.results.getSubs().get(0).getObjects().get(0).getCount()).isEqualTo(1);
+ assertThat(assetCountResponse.results.getSubs().get(0).getObjects().get(0).getValue()).isEqualTo(metaValue3);
+ assertThat(assetCountResponse.results.getSubs().get(0).getObjects().get(1).getCount()).isEqualTo(1);
+ assertThat(assetCountResponse.results.getSubs().get(0).getObjects().get(1).getValue()).isEqualTo(metaValue2);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("2 EPG programs with the same meta (Country) value and pass the meta name in the count request")
+ @Test
+ private void groupByEPGMeta() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(EPG_ID.getValue(), String.valueOf(program.getId()))
+ .equal(EPG_ID.getValue(),String.valueOf(program2.getId()))
+ .closeOr()
+ .toString();
+
+ SearchAssetFilter searchAssetFilter = new SearchAssetFilter();
+ searchAssetFilter.setKSql(query);
+ searchAssetFilter.setTypeIn("0");
+
+ ArrayList arrayList = new ArrayList<>();
+ AssetMetaOrTagGroupBy assetMetaOrTagGroupBy = new AssetMetaOrTagGroupBy();
+ assetMetaOrTagGroupBy.setValue(epgMetaName);
+ arrayList.add(assetMetaOrTagGroupBy);
+
+ searchAssetFilter.setGroupBy(arrayList);
+ CountAssetBuilder countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+
+ // asset/action/count - 2 EPG in count
+ Response assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(2);
+ }
+
+ // TODO
+ @Description("2 EPG programs with the same tag (Director) value and pass the tag name in the count request")
+ @Test
+ private void groupByEPGTag() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(EPG_ID.getValue(), String.valueOf(program.getId()))
+ .equal(EPG_ID.getValue(),String.valueOf(program2.getId()))
+ .closeOr()
+ .toString();
+
+ SearchAssetFilter searchAssetFilter = new SearchAssetFilter();
+ searchAssetFilter.setKSql(query);
+ searchAssetFilter.setTypeIn("0");
+
+ ArrayList arrayList = new ArrayList<>();
+ AssetMetaOrTagGroupBy assetMetaOrTagGroupBy = new AssetMetaOrTagGroupBy();
+ assetMetaOrTagGroupBy.setValue(sharedTagName);
+ arrayList.add(assetMetaOrTagGroupBy);
+
+ searchAssetFilter.setGroupBy(arrayList);
+ CountAssetBuilder countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+
+ // asset/action/count - 2 EPG in count
+ Response assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(2);
+ }
+
+
+ @Description("VOD and EPG program with the same tag value")
+ @Test
+ private void groupByEPGAndVODTag() {
+ String query = new KsqlBuilder()
+ .equal(sharedTagName, sharedTagValue)
+ .toString();
+
+ SearchAssetFilter searchAssetFilter = new SearchAssetFilter();
+ searchAssetFilter.setKSql(query);
+
+ ArrayList arrayList = new ArrayList<>();
+ AssetMetaOrTagGroupBy assetMetaOrTagGroupBy = new AssetMetaOrTagGroupBy();
+ assetMetaOrTagGroupBy.setValue(sharedTagName);
+ arrayList.add(assetMetaOrTagGroupBy);
+
+ searchAssetFilter.setGroupBy(arrayList);
+ CountAssetBuilder countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+
+ // asset/action/count - no filtering (1 VOD asset and 2 EPG programs in count)
+ Response assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(3);
+
+ // asset/action/count - filter by movie type id (1 VOD asset in count)
+ searchAssetFilter.setTypeIn(String.valueOf(getMediaTypeId(MediaType.MOVIE)));
+ countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+ assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(1);
+
+ // asset/action/count - filter by EPG type id (2 EPG programs in count)
+ searchAssetFilter.setTypeIn("0");
+ countAssetBuilder = AssetService.count(searchAssetFilter)
+ .setKs(BaseTest.getAnonymousKs());
+ assetCountResponse = executor.executeSync(countAssetBuilder);
+ assertThat(assetCountResponse.results.getCount()).isEqualTo(2);
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetGetTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetGetTests.java
new file mode 100644
index 000000000..76d1cd958
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetGetTests.java
@@ -0,0 +1,90 @@
+package com.kaltura.client.test.tests.servicesTests.AssetTests;
+
+import com.kaltura.client.enums.AssetReferenceType;
+import com.kaltura.client.services.AssetService;
+import com.kaltura.client.test.tests.BaseTest;
+
+import com.kaltura.client.test.utils.AssetUtils;
+import com.kaltura.client.test.utils.dbUtils.DBUtils;
+import com.kaltura.client.types.Asset;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+
+import static com.kaltura.client.test.utils.BaseUtils.getAPIExceptionFromList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static com.kaltura.client.services.AssetService.*;
+
+public class AssetGetTests extends BaseTest {
+
+ private Long assetId;
+ private int fileId1;
+ private int fileId2;
+ private Long epgProgram;
+
+
+ @BeforeClass
+ private void Asset_get_before_class() {
+ assetId = BaseTest.getSharedMediaAsset().getId();
+ fileId1 = AssetUtils.getAssetFileIds(String.valueOf(assetId)).get(0);
+ fileId2 = AssetUtils.getAssetFileIds(String.valueOf(assetId)).get(1);
+ epgProgram = BaseTest.getSharedEpgProgram().getId();
+
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Asset/action/get - VOD")
+ @Test
+ private void getVodAsset() {
+ GetAssetBuilder getAssetBuilder = AssetService.get(String.valueOf(assetId), AssetReferenceType.MEDIA)
+ .setKs(BaseTest.SharedHousehold.getSharedMasterUserKs());
+ Response assetGetResponse = executor.executeSync(getAssetBuilder);
+
+ assertThat(assetGetResponse.results.getId()).isEqualTo(assetId);
+ assertThat(assetGetResponse.results.getMediaFiles().get(0).getId()).isEqualTo(fileId1);
+ assertThat(assetGetResponse.results.getMediaFiles().get(1).getId()).isEqualTo(fileId2);
+ }
+
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Asset/action/get - EPG")
+ @Test
+ private void getEpgProgram() {
+ GetAssetBuilder getAssetBuilder = AssetService.get(String.valueOf(epgProgram), AssetReferenceType.EPG_INTERNAL)
+ .setKs(BaseTest.SharedHousehold.getSharedMasterUserKs());
+ Response assetGetResponse = executor.executeSync(getAssetBuilder);
+
+ assertThat(assetGetResponse.results.getId()).isEqualTo(epgProgram);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Asset/action/get - un active vod")
+ @Test
+ private void getUnactiveVodAsset() {
+
+ int unactiveAssetId = DBUtils.getUnActiveAsset();
+
+ GetAssetBuilder getAssetBuilder = AssetService.get(String.valueOf(unactiveAssetId), AssetReferenceType.MEDIA)
+ .setKs(BaseTest.SharedHousehold.getSharedMasterUserKs());
+ Response assetGetResponse = executor.executeSync(getAssetBuilder);
+
+ // KalturaAPIException - code: 500007, message: "Asset not found"
+ assertThat(assetGetResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500007).getCode());
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Description("Asset/action/get - invalid asset id")
+ @Test
+ private void getWithInvalidAssetId() {
+ GetAssetBuilder getAssetBuilder = AssetService.get(String.valueOf(assetId + "1"), AssetReferenceType.MEDIA)
+ .setKs(BaseTest.SharedHousehold.getSharedMasterUserKs());
+ Response assetGetResponse = executor.executeSync(getAssetBuilder);
+
+ // KalturaAPIException - code: 500007, message: "Asset not found"
+ assertThat(assetGetResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500007).getCode());
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/BundleFilterTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/BundleFilterTests.java
new file mode 100644
index 000000000..8d70fff54
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/BundleFilterTests.java
@@ -0,0 +1,226 @@
+package com.kaltura.client.test.tests.servicesTests.AssetTests.AssetListTests;
+
+import com.kaltura.client.enums.AssetOrderBy;
+import com.kaltura.client.enums.BundleType;
+import com.kaltura.client.services.ChannelService;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.utils.KsqlBuilder;
+import com.kaltura.client.test.utils.ingestUtils.IngestMppUtils;
+import com.kaltura.client.types.*;
+import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+import static com.kaltura.client.services.AssetService.list;
+import static com.kaltura.client.services.ChannelService.add;
+import static com.kaltura.client.test.Properties.DEFAULT_COLLECTION;
+import static com.kaltura.client.test.Properties.getProperty;
+import static com.kaltura.client.test.tests.enums.KsqlKey.MEDIA_ID;
+import static com.kaltura.client.test.tests.enums.MediaType.*;
+import static com.kaltura.client.test.utils.AssetUtils.getAssets;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.*;
+import static com.kaltura.client.test.utils.ingestUtils.IngestMppUtils.MppData;
+import static com.kaltura.client.test.utils.ingestUtils.IngestMppUtils.insertMpp;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.fail;
+
+public class BundleFilterTests extends BaseTest {
+ private MediaAsset movie1, movie2;
+ private MediaAsset series1, series2;
+ private MediaAsset episode1, episode2;
+ private DynamicChannel channel1, channel2;
+ private Subscription subscription;
+
+
+ @BeforeClass
+ private void asset_list_bundleFilter_before_class() {
+ // get movie
+ List medias = getAssets(2, MOVIE);
+ movie1 = medias.get(0);
+ movie2 = medias.get(1);
+
+ // get series
+ List series = getAssets(2, SERIES);
+ series1 = series.get(0);
+ series2 = series.get(1);
+
+ // get episode
+ List episodes = getAssets(2, EPISODE);
+ episode1 = episodes.get(0);
+ episode2 = episodes.get(1);
+
+ // add assets to channel query 1
+ String channel1Query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), String.valueOf(movie1.getId()))
+ .equal(MEDIA_ID.getValue(), String.valueOf(series1.getId()))
+ .equal(MEDIA_ID.getValue(), String.valueOf(episode1.getId()))
+ .closeOr()
+ .toString();
+
+ // add assets to channel query 2
+ String channel2Query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), String.valueOf(movie2.getId()))
+ .equal(MEDIA_ID.getValue(), String.valueOf(series2.getId()))
+ .equal(MEDIA_ID.getValue(), String.valueOf(episode2.getId()))
+ .closeOr()
+ .toString();
+
+ // add channel1
+ channel1 = new DynamicChannel();
+ channel1.setMultilingualName(setTranslationToken("channel_" + getEpoch()));
+ channel1.setMultilingualDescription(setTranslationToken("Description of " + channel1.getName()));
+ channel1.setSystemName(channel1.getMultilingualName().get(0).getValue() + getRandomValue(""));
+ channel1.setIsActive(true);
+ channel1.setKSql(channel1Query);
+
+ channel1 = (DynamicChannel) executor.executeSync(add(channel1)
+ .setKs(getOperatorKs())
+ .setLanguage("*"))
+ .results;
+
+ // add channel2
+ channel2 = new DynamicChannel();
+ channel2.setMultilingualName(setTranslationToken("channel_" + getEpoch()));
+ channel2.setMultilingualDescription(setTranslationToken("Description of " + channel2.getName()));
+ channel2.setSystemName(channel2.getMultilingualName().get(0).getValue() + getRandomValue(""));
+ channel2.setIsActive(true);
+ channel2.setKSql(channel2Query);
+
+ channel2 = (DynamicChannel) executor.executeSync(add(channel2)
+ .setKs(getOperatorKs())
+ .setLanguage("*"))
+ .results;
+
+ // ingest subscription with 2 new channels
+ MppData mppData = new MppData()
+ .channel1(channel1.getMultilingualName().get(0).getValue())
+ .channel2(channel2.getMultilingualName().get(0).getValue());
+ subscription = insertMpp(mppData);
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - bundleFilter - idEqual - subscription")
+ @Test
+ private void list_assets_with_bundleFilter_subscription_by_idEqual() {
+ // set bundleFilter
+ BundleFilter filter = new BundleFilter();
+ filter.setIdEqual(Integer.valueOf(subscription.getId()));
+ filter.setOrderBy(AssetOrderBy.NAME_ASC.getValue());
+
+ // get list
+ ListResponse assetListResponse = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs())).results;
+
+ // assert response
+ assertThat(assetListResponse.getTotalCount()).isEqualTo(6);
+
+ assertThat(assetListResponse.getObjects()).extracting("id")
+ .containsExactlyInAnyOrder(movie1.getId(), episode1.getId(), series1.getId(), movie2.getId(),
+ episode2.getId(), series2.getId());
+
+ assertThat(assetListResponse.getObjects()).extracting("name")
+ .isSorted();
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - bundleFilter - idEqual and typeIn - subscription")
+ @Test
+ private void list_assets_with_bundleFilter_subscription_by_idEqual_and_typeIn() {
+ // adding "MOVIE", "SERIES" and "LINEAR" to string types (excluding "EPISODE")
+ String types = getConcatenatedString(String.valueOf(getMediaTypeId(MOVIE)),
+ String.valueOf(getMediaTypeId(SERIES)),
+ String.valueOf(getMediaTypeId(LINEAR)));
+
+ // set bundleFilter
+ BundleFilter filter = new BundleFilter();
+ filter.setBundleTypeEqual(BundleType.SUBSCRIPTION);
+ filter.setIdEqual(Integer.valueOf(subscription.getId()));
+ filter.setTypeIn(types);
+
+ // get list
+ ListResponse assetListResponse = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs())).results;
+
+ // assert response
+ assertThat(assetListResponse.getTotalCount()).isEqualTo(4);
+
+ assertThat(assetListResponse.getObjects()).extracting("id")
+ .containsExactlyInAnyOrder(movie1.getId(), movie2.getId(), series1.getId(), series2.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - bundleFilter - idEqual and typeIn - collection")
+ @Test
+ private void list_assets_with_bundleFilter_collection_by_idEqual_and_typeIn() {
+ // set bundleFilter
+ BundleFilter filter = new BundleFilter();
+ filter.setBundleTypeEqual(BundleType.COLLECTION);
+ filter.setIdEqual(Integer.valueOf(getProperty(DEFAULT_COLLECTION)));
+
+ // get full list
+ List assets = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs()))
+ .results
+ .getObjects();
+
+ Asset movie = null;
+ for (Asset asset : assets) {
+ if (asset.getType() == getMediaTypeId(MOVIE)) {
+ movie = asset;
+ break;
+ }
+ }
+
+ if (movie == null){
+ fail("Please add movie asset into the channel related to the provided collection");
+ }
+
+ // get movies list
+ filter.setTypeIn(String.valueOf(getMediaTypeId(MOVIE)));
+ ListResponse assetListResponse = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs())).results;
+
+ // assert response
+ assertThat(assetListResponse.getTotalCount()).isEqualTo(1);
+
+ assertThat(assetListResponse.getObjects()).extracting("id")
+ .containsExactly(movie.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - bundleFilter - subscription - idEqual and collection bundleType")
+ @Test
+ private void list_assets_with_bundleFilter_by_subscription_idEqual_and_collection_bundleType() {
+ // set bundleFilter
+ BundleFilter filter = new BundleFilter();
+ filter.setBundleTypeEqual(BundleType.COLLECTION);
+ filter.setIdEqual(Integer.valueOf(subscription.getId()));
+
+ // get list
+ ListResponse assetListResponse = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs())).results;
+
+ // assert response
+ assertThat(assetListResponse.getTotalCount()).isEqualTo(0);
+ }
+
+ @AfterClass
+ private void asset_list_bundleFilter_after_class() {
+ // delete channels
+ executor.executeSync(ChannelService.delete(Math.toIntExact(channel1.getId()))
+ .setKs(getOperatorKs()));
+
+ executor.executeSync(ChannelService.delete(Math.toIntExact(channel2.getId()))
+ .setKs(getOperatorKs()));
+
+ // delete subscription
+ IngestMppUtils.deleteMpp(subscription.getName());
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/ChannelFilterTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/ChannelFilterTests.java
new file mode 100644
index 000000000..f0a0248e5
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/ChannelFilterTests.java
@@ -0,0 +1,140 @@
+package com.kaltura.client.test.tests.servicesTests.AssetTests.AssetListTests;
+
+import com.kaltura.client.services.ChannelService;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.MediaType;
+import com.kaltura.client.test.utils.KsqlBuilder;
+import com.kaltura.client.types.*;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import static com.kaltura.client.services.AssetService.list;
+import static com.kaltura.client.test.tests.enums.KsqlKey.EPG_ID;
+import static com.kaltura.client.test.tests.enums.KsqlKey.MEDIA_ID;
+import static com.kaltura.client.test.utils.AssetUtils.getAssets;
+import static com.kaltura.client.test.utils.AssetUtils.getPrograms;
+import static com.kaltura.client.test.utils.BaseUtils.getEpoch;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getAPIExceptionFromList;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.setTranslationToken;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ChannelFilterTests extends BaseTest {
+
+ private MediaAsset asset1, asset2, asset3;
+ private ProgramAsset program1;
+ private DynamicChannel channel;
+
+
+ @BeforeClass
+ private void asset_list_channelFilter_before_class() {
+ // get movie
+ asset1 = getAssets(1, MediaType.MOVIE).get(0);
+
+ // get series
+ asset2 = getAssets(1, MediaType.SERIES).get(0);
+
+ // get episode
+ asset3 = getAssets(1, MediaType.EPISODE).get(0);
+
+ // get epg
+ program1 = getPrograms(1).get(0);
+
+ // add assets to channel query
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), String.valueOf(asset1.getId()))
+ .equal(MEDIA_ID.getValue(), String.valueOf(asset2.getId()))
+ .equal(MEDIA_ID.getValue(), String.valueOf(asset3.getId()))
+ .equal(EPG_ID.getValue(), String.valueOf(program1.getId()))
+ .closeOr()
+ .toString();
+
+ // add channel
+ channel = new DynamicChannel();
+ channel.setMultilingualName(setTranslationToken("channel_" + getEpoch()));
+ channel.setMultilingualDescription(setTranslationToken("Description of " + channel.getName()));
+ channel.setSystemName(channel.getMultilingualName().get(0).getValue());
+ channel.setIsActive(true);
+ channel.setKSql(query); // "Free='" + channel.getName() + "'"
+
+ channel = (DynamicChannel) executor.executeSync(ChannelService.add(channel)
+ .setKs(getOperatorKs())
+ .setLanguage("*"))
+ .results;
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - channelFilter - idEqual")
+ @Test
+ private void list_assets_with_channelFilter_by_channelId() {
+ // set channelFilter
+ ChannelFilter filter = new ChannelFilter();
+ filter.setIdEqual(Math.toIntExact(channel.getId()));
+
+ // get list
+ ListResponse assetListResponse = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs())).results;
+
+ // assert response
+ assertThat(assetListResponse.getTotalCount()).isEqualTo(4);
+ assertThat(assetListResponse.getObjects()).extracting("id")
+ .containsExactlyInAnyOrder(asset1.getId(), asset2.getId(), asset3.getId(), program1.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - channelFilter - idEqual and KSql")
+ @Test
+ private void list_assets_with_channelFilter_by_channelId_and_ksql() {
+ // build query
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), String.valueOf(asset1.getId()))
+ .equal(EPG_ID.getValue(), String.valueOf(program1.getId()))
+ .closeOr()
+ .toString();
+
+ // set channelFilter
+ ChannelFilter filter = new ChannelFilter();
+ filter.setIdEqual(Math.toIntExact(channel.getId()));
+ filter.setKSql(query);
+
+ // get list
+ ListResponse assetListResponse = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs())).results;
+
+ // assert response
+ assertThat(assetListResponse.getTotalCount()).isEqualTo(2);
+ assertThat(assetListResponse.getObjects()).extracting("id")
+ .containsExactlyInAnyOrder(asset1.getId(), program1.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - with invalid channelId")
+ @Test
+ private void list_vod_assets_with_channelFilter_by_channelId_and_ksql() {
+ // set channelFilter
+ int invalidChannelId = 1;
+ ChannelFilter filter = new ChannelFilter();
+ filter.setIdEqual(invalidChannelId);
+
+ // get list
+ Response> assetListResponse = executor.executeSync(list(filter)
+ .setKs(getAnonymousKs()));
+
+ // assert response
+ assertThat(assetListResponse.results).isNull();
+ assertThat(assetListResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(4018).getCode());
+ }
+
+ @AfterClass
+ private void asset_list_channelFilter_after_class() {
+ // delete channel
+ executor.executeSync(ChannelService.delete(Math.toIntExact(channel.getId()))
+ .setKs(getOperatorKs()));
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/RelatedFilterTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/RelatedFilterTests.java
new file mode 100644
index 000000000..5cb6a0c28
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/RelatedFilterTests.java
@@ -0,0 +1,5 @@
+package com.kaltura.client.test.tests.servicesTests.AssetTests.AssetListTests;
+
+public class RelatedFilterTests {
+ // TODO: 7/9/2018 implement RelatedFilterTests
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/ScheduledRecordingProgramFilterTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/ScheduledRecordingProgramFilterTests.java
new file mode 100644
index 000000000..3e5f549bc
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/ScheduledRecordingProgramFilterTests.java
@@ -0,0 +1,200 @@
+package com.kaltura.client.test.tests.servicesTests.AssetTests.AssetListTests;
+
+import com.kaltura.client.enums.RecordingStatus;
+import com.kaltura.client.services.AssetService;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.PremiumService;
+import com.kaltura.client.test.utils.HouseholdUtils;
+import com.kaltura.client.test.utils.dbUtils.DBUtils;
+import com.kaltura.client.types.*;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.json.JSONArray;
+import org.json.JSONObject;
+import org.testng.annotations.AfterClass;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.Calendar;
+import java.util.List;
+import java.util.Optional;
+
+import static com.kaltura.client.services.HouseholdService.delete;
+import static com.kaltura.client.services.RecordingService.add;
+import static com.kaltura.client.test.utils.BaseUtils.*;
+import static com.kaltura.client.test.utils.HouseholdUtils.createHousehold;
+import static com.kaltura.client.test.utils.PurchaseUtils.purchasePpv;
+import static com.kaltura.client.test.utils.PurchaseUtils.purchaseSubscription;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getSubscriptionWithPremiumService;
+import static com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils.EpgData;
+import static com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils.insertEpg;
+import static org.assertj.core.api.Assertions.assertThat;
+
+public class ScheduledRecordingProgramFilterTests extends BaseTest {
+
+ private int linearAssetId1, linearAssetId2;
+ private JSONObject linearAssetJsonObject1, linearAssetJsonObject2;
+ private String masterUserKs;
+ private List programAssets1, programAssets2;
+
+
+ @BeforeClass
+ private void asset_list_scheduledRecordingProgramFilter_before_class() {
+ // create household
+ Household household = createHousehold();
+ String udid = HouseholdUtils.getDevicesList(household).get(0).getUdid();
+ masterUserKs = HouseholdUtils.getHouseholdMasterUserKs(household, udid);
+
+ // purchase subscription with npvr premium service
+ Subscription subscription = getSubscriptionWithPremiumService(PremiumService.NPVR);
+ purchaseSubscription(masterUserKs, Integer.parseInt(subscription.getId()), Optional.empty());
+
+ // get linearAsset and epg channelId
+ JSONArray jsonArray = DBUtils.getLinearAssetIdAndEpgChannelNameJsonArray();
+ linearAssetJsonObject1 = jsonArray.getJSONObject(0);
+ linearAssetJsonObject2 = jsonArray.getJSONObject(1);
+
+ linearAssetId1 = linearAssetJsonObject1.getInt("media_id");
+ linearAssetId2 = linearAssetJsonObject2.getInt("media_id");
+
+ // purchase linearAsset
+ purchasePpv(masterUserKs, Optional.of(linearAssetId1), Optional.empty(), Optional.empty());
+ purchasePpv(masterUserKs, Optional.of(linearAssetId2), Optional.empty(), Optional.empty());
+
+ // ingest epg's
+ EpgData epgData1 = new EpgData(linearAssetJsonObject1.getString("name"))
+ .startDate(getEpoch(Calendar.MINUTE, 5));
+ programAssets1 = insertEpg(epgData1);
+
+// String seriesId = String.valueOf(getEpochInLocalTime());
+ EpgData epgData2 = new EpgData(linearAssetJsonObject2.getString("name"))
+ .startDate(getEpoch(Calendar.HOUR, 6));
+// .seriesId(seriesId)
+// .seasonsNum(3);
+ programAssets2 = insertEpg(epgData2);
+
+ // add recordings 1
+ Recording recording1 = new Recording();
+ recording1.setAssetId(programAssets1.get(0).getId());
+
+ Response recordingResponse = executor.executeSync(add(recording1).setKs(masterUserKs));
+ assertThat(recordingResponse.results.getStatus()).isEqualTo(RecordingStatus.SCHEDULED);
+
+ // add recordings 2
+ Recording recording2 = new Recording();
+ recording2.setAssetId(programAssets2.get(0).getId());
+
+ recordingResponse = executor.executeSync(add(recording2).setKs(masterUserKs));
+ assertThat(recordingResponse.results.getStatus()).isEqualTo(RecordingStatus.SCHEDULED);
+
+// // add series recording
+// SeriesRecording seriesRecording = new SeriesRecording();
+// seriesRecording.setChannelId(linearAssetJsonObject2.getLong("id"));
+// seriesRecording.setSeasonNumber(1);
+// seriesRecording.setType(RecordingType.SERIES);
+// seriesRecording.setEpgId();
+//
+// Response seriesRecordingResponse = executor.executeSync(SeriesRecordingService.add(seriesRecording)
+// .setKs(masterUserKs));
+//// assertThat(seriesRecordingResponse.results.getStatus()).isEqualTo(RecordingStatus.SCHEDULED);
+
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - scheduledRecordingProgramFilter - channelsIn")
+ @Test
+ private void list_assets_with_channelFilter_by_channelId() {
+ // set scheduledRecordingProgramFilter
+ ScheduledRecordingProgramFilter filter = new ScheduledRecordingProgramFilter();
+ String channelsIn = getConcatenatedString(String.valueOf(linearAssetJsonObject1.getInt("id")),
+ String.valueOf(linearAssetJsonObject2.getInt("id")));
+ filter.setChannelsIn(channelsIn);
+
+ // get list
+ Response> assetListResponse = executor.executeSync(AssetService.list(filter)
+ .setKs(masterUserKs));
+
+ // assert response
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(2);
+
+ assertThat(assetListResponse.results.getObjects()).extracting("id")
+ .containsExactlyInAnyOrder(programAssets1.get(0).getId(), programAssets2.get(0).getId());
+
+ assertThat(assetListResponse.results.getObjects()).extracting("name")
+ .containsExactlyInAnyOrder(programAssets1.get(0).getName(), programAssets2.get(0).getName());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - scheduledRecordingProgramFilter - startDateGreaterThanOrNull")
+ @Test
+ private void list_assets_with_channelFilter_by_startDateGreaterThanOrNull() {
+ // set scheduledRecordingProgramFilter
+ String channelsIn = getConcatenatedString(String.valueOf(linearAssetJsonObject1.getInt("id")),
+ String.valueOf(linearAssetJsonObject2.getInt("id")));
+
+ ScheduledRecordingProgramFilter filter = new ScheduledRecordingProgramFilter();
+ filter.setChannelsIn(channelsIn);
+ filter.setStartDateGreaterThanOrNull(getEpoch(Calendar.HOUR, 3));
+
+ // get list
+ Response> assetListResponse = executor.executeSync(AssetService.list(filter)
+ .setKs(masterUserKs));
+
+ // assert response
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(programAssets2.get(0).getId());
+ assertThat(assetListResponse.results.getObjects().get(0).getName()).isEqualTo(programAssets2.get(0).getName());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - scheduledRecordingProgramFilter - setEndDateLessThanOrNull")
+ @Test(enabled = true)
+ private void list_assets_with_channelFilter_by_setEndDateLessThanOrNull() {
+ // set scheduledRecordingProgramFilter
+ String channelsIn = getConcatenatedString(String.valueOf(linearAssetJsonObject1.getInt("id")),
+ String.valueOf(linearAssetJsonObject2.getInt("id")));
+
+ ScheduledRecordingProgramFilter filter = new ScheduledRecordingProgramFilter();
+ filter.setChannelsIn(channelsIn);
+ filter.setEndDateLessThanOrNull(getEpoch(Calendar.HOUR, 1));
+
+ // get list
+ Response> assetListResponse = executor.executeSync(AssetService.list(filter)
+ .setKs(masterUserKs));
+
+ // assert response
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(programAssets1.get(0).getId());
+ assertThat(assetListResponse.results.getObjects().get(0).getName()).isEqualTo(programAssets1.get(0).getName());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - scheduledRecordingProgramFilter - setRecordingTypeEqual")
+ @Test(enabled = false)
+ private void list_assets_with_channelFilter_by_setRecordingTypeEqual() {
+// // set scheduledRecordingProgramFilter
+// String channelsIn = getConcatenatedString(String.valueOf(linearAssetJsonObject1.getInt("id")),
+// String.valueOf(linearAssetJsonObject2.getInt("id")));
+//
+// ScheduledRecordingProgramFilter filter = new ScheduledRecordingProgramFilter();
+// filter.setChannelsIn(channelsIn);
+// filter.setRecordingTypeEqual(ScheduledRecordingAssetType.SERIES);
+//
+// // get list
+// Response> assetListResponse = executor.executeSync(AssetService.list(filter)
+// .setKs(masterUserKs));
+//
+// // assert response
+// assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+// assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(programAssets1.get(0).getId());
+// assertThat(assetListResponse.results.getObjects().get(0).getName()).isEqualTo(programAssets1.get(0).getName());
+ }
+
+ @AfterClass
+ private void asset_list_scheduledRecordingProgramFilter_after_class() {
+ // cleanup
+ executor.executeSync(delete().setKs(masterUserKs));
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/SearchAssetFilterTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/SearchAssetFilterTests.java
new file mode 100644
index 000000000..baed57634
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/AssetTests/AssetListTests/SearchAssetFilterTests.java
@@ -0,0 +1,628 @@
+package com.kaltura.client.test.tests.servicesTests.AssetTests.AssetListTests;
+
+import com.kaltura.client.enums.AssetOrderBy;
+import com.kaltura.client.enums.AssetType;
+import com.kaltura.client.enums.MetaTagOrderBy;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.KsqlKey;
+import com.kaltura.client.test.utils.HouseholdUtils;
+import com.kaltura.client.test.utils.KsqlBuilder;
+import com.kaltura.client.test.utils.PurchaseUtils;
+import com.kaltura.client.types.*;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Description;
+import io.qameta.allure.Issue;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.json.JSONArray;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.*;
+import java.util.concurrent.TimeUnit;
+
+import static com.kaltura.client.services.AssetService.ListAssetBuilder;
+import static com.kaltura.client.services.AssetService.list;
+import static com.kaltura.client.test.tests.BaseTest.SharedHousehold.getSharedMasterUserKs;
+import static com.kaltura.client.test.tests.enums.KsqlKey.*;
+import static com.kaltura.client.test.tests.enums.MediaType.EPISODE;
+import static com.kaltura.client.test.tests.enums.MediaType.MOVIE;
+import static com.kaltura.client.test.utils.AssetUtils.*;
+import static com.kaltura.client.test.utils.BaseUtils.getRandomValue;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getLinearAssetIdAndEpgChannelNameJsonArray;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getMediaTypeId;
+import static com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils.EpgData;
+import static com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils.insertEpg;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.*;
+import static java.util.TimeZone.getTimeZone;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+public class SearchAssetFilterTests extends BaseTest {
+
+ private final String tagName = "Genre";
+ private final String metaName = "synopsis";
+ private final String metaName2 = "Short title";
+ private final String metaValue1 = "A" + getRandomValue("_");
+ private final String metaValue2 = "B" + getRandomValue("_");
+
+ private MediaAsset asset, asset2, asset3;
+ private ProgramAsset program, program2;
+ private String tagValue, masterUserKs;
+ private AssetFilter assetFilter;
+ private String geoBlockRule = "Philippines Only";
+
+
+
+ @BeforeClass(alwaysRun = true)
+ private void asset_list_searchAssetFilter_before_class() {
+ // Get asset from shared asset method
+ tagValue = getRandomValue(tagName + "_");
+
+ ArrayList list = new ArrayList<>();
+ list.add(tagValue);
+
+ HashMap> tagMap = new HashMap<>();
+ tagMap.put(tagName, list);
+
+ HashMap stringMetaMap1 = new HashMap<>();
+ stringMetaMap1.put(metaName, metaValue1);
+ stringMetaMap1.put(metaName2, metaValue1);
+
+ HashMap stringMetaMap2 = new HashMap<>();
+ stringMetaMap2.put(metaName, metaValue2);
+
+ JSONArray ja = getLinearAssetIdAndEpgChannelNameJsonArray();
+ String epgChannelName = ja.getJSONObject(0).getString("name");
+ String epgChannelName2 = ja.getJSONObject(1).getString("name");
+
+ // ingest asset 1
+ VodData vodData1 = new VodData()
+ .mediaType(MOVIE);
+ asset = insertVod(vodData1, true);
+
+ // ingest asset 2
+ VodData vodData2 = new VodData()
+ .mediaType(MOVIE)
+ .catalogStartDate(getFormattedTime(Calendar.MINUTE,-100, getTimeZone("UTC")))
+ .tags(tagMap)
+ .stringsMeta(stringMetaMap1)
+ .geoBlockRule(geoBlockRule);
+
+ asset2 = insertVod(vodData2, true);
+
+ // ingest asset 3
+ VodData vodData3 = new VodData()
+ .mediaType(EPISODE)
+ .catalogStartDate(getFormattedTime(Calendar.MINUTE,-10, getTimeZone("UTC")))
+ .tags(tagMap)
+ .stringsMeta(stringMetaMap2);
+ asset3 = insertVod(vodData3, true);
+
+ // ingest epg 1
+ EpgData epgData1 = new EpgData(epgChannelName).episodesNum(1);
+ program = insertEpg(epgData1).get(0);
+
+ // ingest epg 2
+ EpgData epgData2 = new EpgData(epgChannelName2).episodesNum(1);
+ program2 = insertEpg(epgData2).get(0);
+
+ Household household = HouseholdUtils.createHousehold();
+ masterUserKs = HouseholdUtils.getHouseholdMasterUserKs(household);
+
+ PurchaseUtils.purchasePpv(masterUserKs, Optional.of(asset.getId().intValue()), Optional.empty(), Optional.empty());
+ }
+
+ // Filter by KSQL
+ // *********************
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - filter by geo blocked assets." +
+ "The filter return only asset that are not blocked for playback because of geo restriction")
+ @Test
+ private void listVodAssetsByGeoBlock() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .closeOr()
+ .equal(GEO_BLOCK.getValue(), "true")
+ .closeAnd()
+ .toString();
+
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(masterUserKs));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ // Only asset 1 returned (asset 2 has geo block rule)
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset.getId());
+ }
+
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - filter by entitled asset")
+ @Test
+ private void listVodAssetsByEntitled() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .closeOr()
+ .equal(ENTITLED_ASSETS.getValue(), "entitled")
+ .closeAnd()
+ .toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(masterUserKs));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - filter by asset name")
+ @Test
+ private void listVodAssetsByAssetName() {
+ String query = new KsqlBuilder().equal("name", asset.getName()).toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Reserved key: asset/action/list - VOD - filter by media_id")
+ @Test
+ private void listVodAssetsByMediaId() {
+ String query = new KsqlBuilder().equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId())).toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - filter by meta")
+ @Test
+ private void listVodAssetsByMeta() {
+ String query = new KsqlBuilder().equal(metaName, metaValue1).toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset2.getId());
+ }
+
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Logical conjunction: asset/action/list - VOD - OR query")
+ @Test
+ private void listVodAssetsWithOrQuery() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .closeOr()
+ .toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(2);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Logical conjunction: asset/action/list - VOD - AND query")
+ @Test
+ private void listVodAssetsWithAndQuery() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .equal(tagName, tagValue)
+ .closeAnd()
+ .toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset3.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Alpha numeric field: asset/action/list - VOD - not query")
+ @Test
+ private void listVodAssetsWithNotKsqlQuery() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .notEqual(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .equal(tagName, tagValue)
+ .closeAnd()
+ .toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset2.getId());
+ }
+
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Alpha numeric field: asset/action/list - VOD - with existing meta value (+)")
+ @Test
+ private void listVodAssetsWithExistingMetaValue() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .closeOr()
+ .exists(metaName2)
+ .closeAnd()
+ .toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset2.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Alpha numeric field: asset/action/list - VOD - like query")
+ @Test
+ private void listVodAssetsWithLikeKsqlQuery() {
+ String query = new KsqlBuilder().like(tagName, tagValue).toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ List assets = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()))
+ .results
+ .getObjects();
+
+ assertThat(assets).isNotNull();
+ assertThat(assets.size()).isEqualTo(2);
+ assertThat(assets).extracting("id").contains(asset3.getId(), asset2.getId()).doesNotContain(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("Alpha numeric field: asset/action/list - VOD - start with query")
+ @Test
+ private void listVodAssetsWithStartWithKsqlQuery() {
+ String query = new KsqlBuilder().startsWith(tagName, tagValue).toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ List assets = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()))
+ .results
+ .getObjects();
+
+ assertThat(assets).as("assets list").isNotNull();
+ assertThat(assets.size()).isEqualTo(2);
+ assertThat(assets).extracting("id").contains(asset3.getId(), asset2.getId()).doesNotContain(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - filtered by type (Movie)")
+ @Test
+ private void listVodAssetsFilteredByType() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .equal(tagName, tagValue)
+ .equal("asset_type", getMediaTypeId(MOVIE))
+ .closeAnd()
+ .toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results).isNotNull();
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset2.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - order by VIEWS")
+ @Test(groups = "slowBefore")
+ private void orderVodAssetsByViews_before_wait() {
+
+ int numOfActionsAsset = 3;
+ int numOfActionsAsset2 = 2;
+ int numOfActionsAsset3 = 1;
+
+ // Add 3 views to asset
+ for (int i = 0; i < numOfActionsAsset; i++) {
+ addViewToAsset(asset, AssetType.MEDIA);
+ }
+
+ // Add 2 views to asset2
+ for (int i = 0; i < numOfActionsAsset2; i++) {
+ addViewToAsset(asset2, AssetType.MEDIA);
+ }
+
+ // Add 1 view to asset3
+ for (int i = 0; i < numOfActionsAsset3; i++) {
+ addViewToAsset(asset3, AssetType.MEDIA);
+ }
+ }
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - order by VIEWS")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void orderVodAssetsByViews_after_wait() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .closeOr()
+ .toString();
+ assetFilter = getSearchAssetFilter(query, null, null, null, null, AssetOrderBy.VIEWS_DESC.getValue());
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ // wait for pin to expire
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ List assetsList = executor.executeSync(list(assetFilter).setKs(getSharedMasterUserKs())).results.getObjects();
+ return assetsList.get(0).getId().equals(asset.getId()) &&
+ assetsList.get(1).getId().equals(asset2.getId()) &&
+ assetsList.get(2).getId().equals(asset3.getId());
+ });
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.error).isNull();
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(3);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset3.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - order by NAME (DESC/ASC")
+ @Test(enabled = true)
+ private void orderVodAssetsByName() {
+ VodData vodData = new VodData().name("AAA");
+ updateVod(asset.getName(), vodData);
+
+ vodData.name("BBB");
+ updateVod(asset2.getName(), vodData);
+
+ vodData.name("CCC");
+ updateVod(asset3.getName(), vodData);
+
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .closeOr()
+ .toString();
+
+ assetFilter = getSearchAssetFilter(query,null, null, null, null, AssetOrderBy.NAME_ASC.getValue());
+
+ ListAssetBuilder listAssetBuilder = list(assetFilter)
+ .setKs(getSharedMasterUserKs());
+ Response> assetListResponse = executor.executeSync(listAssetBuilder);
+
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset3.getId());
+
+ assetFilter = getSearchAssetFilter(query,null, null, null, null, AssetOrderBy.NAME_DESC.getValue());
+
+ listAssetBuilder = list(assetFilter).setKs(getSharedMasterUserKs());
+ assetListResponse = executor.executeSync(listAssetBuilder);
+
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset3.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - order by LIKES")
+ @Test
+ private void orderVodAssetsByLikes() {
+ addLikesToAsset(asset3.getId(), 3, AssetType.MEDIA);
+ addLikesToAsset(asset2.getId(), 2, AssetType.MEDIA);
+ addLikesToAsset(asset.getId(), 1, AssetType.MEDIA);
+
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .closeOr()
+ .toString();
+ assetFilter = getSearchAssetFilter(query,null, null, null, null, AssetOrderBy.LIKES_DESC.getValue());
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(3);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset3.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - order by (num of) VOTES and RATING")
+ @Test
+ private void orderVodAssetsByVotesAndRating() {
+ addVotesToAsset(asset2.getId(), 2, AssetType.MEDIA, 1);
+ addVotesToAsset(asset3.getId(), 1, AssetType.MEDIA, 5);
+
+ // Order by number of votes (highest to lowest)
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .closeOr()
+ .toString();
+ assetFilter = getSearchAssetFilter(query, null, null, null, null, AssetOrderBy.VOTES_DESC.getValue());
+
+ ListAssetBuilder listAssetBuilder = list(assetFilter)
+ .setKs(getSharedMasterUserKs());
+ Response> assetListResponse = executor.executeSync(listAssetBuilder);
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(3);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset3.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset.getId());
+
+ // Order by Ratings (highest to lowest)
+ assetFilter = getSearchAssetFilter(query, null, null, null, null, AssetOrderBy.RATINGS_DESC.getValue());
+
+ listAssetBuilder = list(assetFilter).setKs(getSharedMasterUserKs());
+ assetListResponse = executor.executeSync(listAssetBuilder);
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(3);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset3.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - order by CATALOG START DATE")
+ @Test
+ private void orderVodAssetsByCatalogStartDate() {
+ String query = new KsqlBuilder()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .closeOr()
+ .toString();
+ assetFilter = getSearchAssetFilter(query, null, null, null, null, AssetOrderBy.START_DATE_DESC.getValue());
+
+ ListAssetBuilder listAssetBuilder = list(assetFilter)
+ .setKs(getSharedMasterUserKs());
+ Response> assetListResponse = executor.executeSync(listAssetBuilder);
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(3);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset3.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset.getId());
+
+ assetFilter = getSearchAssetFilter(query, null, null, null, null, AssetOrderBy.START_DATE_ASC.getValue());
+
+ listAssetBuilder = list(assetFilter).setKs(getSharedMasterUserKs());
+ assetListResponse = executor.executeSync(listAssetBuilder);
+
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(2).getId()).isEqualTo(asset3.getId());
+ }
+
+ @Issue("BEO-5254")
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - VOD - dynamicOrderBy meta (ASC/DESC")
+ @Test(enabled = false)
+
+ private void dynamicOrderByMeta() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .openOr()
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset2.getId()))
+ .equal(MEDIA_ID.getValue(), Math.toIntExact(asset3.getId()))
+ .closeOr()
+ .equal("asset_type", getMediaTypeId(MOVIE))
+ .closeAnd()
+ .toString();
+ DynamicOrderBy dynamicOrderBy = new DynamicOrderBy();
+ dynamicOrderBy.setName(metaName);
+ dynamicOrderBy.setOrderBy(MetaTagOrderBy.META_ASC);
+ assetFilter = getSearchAssetFilter(query, null, dynamicOrderBy, null, null, null);
+
+ ListAssetBuilder listAssetBuilder = list(assetFilter)
+ .setKs(getSharedMasterUserKs());
+ Response> assetListResponse = executor.executeSync(listAssetBuilder);
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(2);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(asset2.getId());
+ assertThat(assetListResponse.results.getObjects().get(1).getId()).isEqualTo(asset3.getId());
+ }
+
+
+ //TODO - add test for KalturaPersistedFilter in searchHistory class
+
+ // EPG
+ // ***************************************************
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - EPG - name equal query")
+ @Test
+ private void listEpgProgramByName() {
+ String query = new KsqlBuilder().equal("name", program.getName()).toString();
+ assetFilter = getSearchAssetFilter(query, "0", null, null, null, null);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(program.getId());
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - EPG - epg channel id equal query")
+ @Test
+ private void listEpgProgramByChannelId() {
+ String query = new KsqlBuilder().equal("epg_channel_id", Math.toIntExact(program.getEpgChannelId())).toString();
+ assetFilter = getSearchAssetFilter(query);
+
+ List epgPrograms = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()))
+ .results
+ .getObjects();
+
+ assertThat(epgPrograms.size()).isGreaterThan(1);
+ assertThat(epgPrograms).extracting("epgChannelId").contains(program.getEpgChannelId());
+ }
+
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("asset/action/list - EPG - filter by epg channel id")
+ @Test
+ private void listEpgProgramsFilteredByEpgChannel() {
+ String query = new KsqlBuilder()
+ .openAnd()
+ .openOr()
+ .equal("name", program.getName())
+ .equal("name", program2.getName())
+ .closeOr()
+ .equal(KsqlKey.EPG_CHANNEL_ID.getValue(), program2.getEpgChannelId().toString())
+ .closeAnd()
+ .toString();
+ assetFilter = getSearchAssetFilter(query, "0", null, null, null, null);
+
+ Response> assetListResponse = executor.executeSync(list(assetFilter)
+ .setKs(getSharedMasterUserKs()));
+
+ assertThat(assetListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetListResponse.results.getObjects().get(0).getId()).isEqualTo(program2.getId());
+ }
+}
\ No newline at end of file
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/announcementTests/AnnouncementAddTest.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/announcementTests/AnnouncementAddTest.java
new file mode 100644
index 000000000..ee53d5937
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/announcementTests/AnnouncementAddTest.java
@@ -0,0 +1,100 @@
+package com.kaltura.client.test.tests.servicesTests.announcementTests;
+
+import com.kaltura.client.enums.AnnouncementRecipientsType;
+import com.kaltura.client.enums.AnnouncementStatus;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.types.Announcement;
+import com.kaltura.client.types.AnnouncementFilter;
+import com.kaltura.client.types.FilterPager;
+import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.Calendar;
+import java.util.List;
+import java.util.concurrent.Callable;
+import java.util.concurrent.TimeUnit;
+
+import static com.kaltura.client.services.AnnouncementService.*;
+import static com.kaltura.client.services.OttUserService.login;
+import static com.kaltura.client.test.utils.BaseUtils.getEpoch;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getAnnouncementResultMessageId;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+public class AnnouncementAddTest extends BaseTest {
+
+ @BeforeClass
+ private void announcement_add_tests_before_class() {
+ executor.executeSync(login(partnerId, "alon2986", "alon2986"));
+ }
+
+ @Severity(SeverityLevel.CRITICAL)
+ @Description("announcement/action/add")
+ @Test(enabled = true)
+ private void addAnnouncement() {
+ // set announcement
+ long epoch = getEpoch(Calendar.MINUTE, 1);
+ Announcement announcement = new Announcement();
+ announcement.setName("Announcement_" + epoch);
+ announcement.setMailSubject(announcement.getName());
+ announcement.setMessage(announcement.getName());
+ announcement.setEnabled(true);
+ announcement.setStartTime(epoch);
+ announcement.setTimezone("UTC");
+ announcement.setRecipients(AnnouncementRecipientsType.ALL);
+
+ // add announcement
+ announcement = executor.executeSync(add(announcement)
+ .setKs(getOperatorKs()))
+ .results;
+
+ // get list of announcements
+ AnnouncementFilter filter = new AnnouncementFilter();
+ filter.setOrderBy("NONE");
+
+ FilterPager pager = new FilterPager();
+ pager.setPageSize(10);
+ pager.setPageIndex(1);
+
+ ListAnnouncementBuilder listAnnouncementBuilder = list(filter, pager).setKs(getOperatorKs());
+
+ // wait until announcement will be send
+ await()
+ .atMost(5, TimeUnit.MINUTES)
+ .pollInterval(30, TimeUnit.SECONDS)
+ .until(isAnnouncementSent(listAnnouncementBuilder, announcement.getId()));
+
+ // assert confirmation from Amazon
+ List ids = getAnnouncementResultMessageId(announcement.getId());
+ assertThat(ids).isNotNull();
+ assertThat(ids.size()).isGreaterThan(0);
+
+ // assert email sent
+// assertThat(isEmailReceived(announcement.getMessage(), true)).isTrue();
+ }
+
+
+
+ // helper methods
+ private static Callable isAnnouncementSent(ListAnnouncementBuilder listAnnouncementBuilder, int announcementId) {
+ return () -> {
+ // get announcement list
+ List announcements = executor.executeSync(listAnnouncementBuilder)
+ .results
+ .getObjects();
+
+ // get created announcement from list
+ Announcement announcement = announcements.stream().
+ filter(a -> a.getId().equals(announcementId)).
+ findFirst()
+ .orElse(null);
+
+ // check if announcement sent
+ return announcement != null &&
+ announcement.getStatus().equals(AnnouncementStatus.SENT);
+ };
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenAddTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenAddTests.java
index e66c4ba9a..15d7cbd1c 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenAddTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenAddTests.java
@@ -4,36 +4,45 @@
import com.kaltura.client.services.AppTokenService;
import com.kaltura.client.test.tests.BaseTest;
import com.kaltura.client.test.utils.AppTokenUtils;
-import com.kaltura.client.test.utils.BaseUtils;
+import com.kaltura.client.types.APIException;
import com.kaltura.client.types.AppToken;
import com.kaltura.client.utils.response.base.Response;
import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import java.util.Calendar;
+import java.util.concurrent.TimeUnit;
+
import static com.kaltura.client.services.AppTokenService.AddAppTokenBuilder;
import static com.kaltura.client.services.AppTokenService.GetAppTokenBuilder;
import static com.kaltura.client.test.tests.BaseTest.SharedHousehold.*;
import static com.kaltura.client.test.utils.BaseUtils.getAPIExceptionFromList;
+import static com.kaltura.client.test.utils.BaseUtils.getEpoch;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
public class AppTokenAddTests extends BaseTest {
private String sessionUserId;
private AppToken appToken;
private String sessionPrivileges;
+ private Response addAppTokenResponseSlowTest;
+ private APIException apiException;;
// TODO: 5/3/2018 Add comments!
- @BeforeClass
+ @BeforeClass(alwaysRun = true)
private void add_tests_before_class() {
sessionUserId = getSharedUser().getUserId();
appToken = AppTokenUtils.addAppToken(sessionUserId, AppTokenHashType.SHA1, null, null);
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/add")
@Test
private void addAppToken() {
-
AddAppTokenBuilder addAppTokenBuilder = AppTokenService.add(appToken)
.setKs(getOperatorKs());
Response appTokenResponse = executor.executeSync(addAppTokenBuilder);
@@ -50,11 +59,12 @@ private void addAppToken() {
assertThat(appTokenResponse.results.getSessionUserId()).isEqualTo(String.valueOf(sessionUserId));
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/add - without hash type")
@Test
private void addAppTokenWithDefaultHashType() {
appToken = AppTokenUtils.addAppToken(sessionUserId, null, null, null);
-
+
// Invoke AppToken/action/add - with no hash type (will return the default hash type)
AddAppTokenBuilder addAppTokenBuilder = AppTokenService.add(appToken)
.setKs(getOperatorKs());
@@ -64,6 +74,7 @@ private void addAppTokenWithDefaultHashType() {
assertThat(appTokenResponse.results.getHashType()).isEqualTo(AppTokenHashType.SHA256);
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/add - with privileges")
@Test
private void addAppTokenWithPrivileges() {
@@ -78,33 +89,44 @@ private void addAppTokenWithPrivileges() {
}
@Description("appToken/action/add - with expiry date")
- @Test(groups = "slow")
- private void addAppTokenWithExpiryDate() {
- Long expiryDate = BaseUtils.getTimeInEpoch(1);
+ // priority needed, because at parralel execution both test threads launch setup method of this class and this cause to Error 1 at login with operator user.
+ @Test(groups = {"slowBefore"}, priority = 1)
+ private void addAppTokenWithExpiryDate_before_wait() {
+ // prepare token with expiration after 1 minute
+ Long expiryDate = getEpoch(Calendar.MINUTE, 1);
appToken = AppTokenUtils.addAppToken(sessionUserId, null, sessionPrivileges, Math.toIntExact(expiryDate));
AddAppTokenBuilder addAppTokenBuilder = AppTokenService.add(appToken)
.setKs(getOperatorKs());
- Response addAppTokenResponse = executor.executeSync(addAppTokenBuilder);
+ addAppTokenResponseSlowTest = executor.executeSync(addAppTokenBuilder);
- assertThat(addAppTokenResponse.results.getExpiry()).isEqualTo(Math.toIntExact(expiryDate));
+ assertThat(addAppTokenResponseSlowTest.results.getExpiry()).isEqualTo(Math.toIntExact(expiryDate));
// Wait until token is expired (according to expiry date)
- System.out.println("Waiting 1 minute until token expiry date reached");
+ System.out.println("Waiting until token expiry date reached");
+ }
- try {
- Thread.sleep(72000);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- GetAppTokenBuilder getAppTokenBuilder = AppTokenService.get(addAppTokenResponse.results.getId())
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void addAppTokenWithExpiryDate_after_wait() {
+ // prepare builder and variables for await() functionality
+ GetAppTokenBuilder getAppTokenBuilder = AppTokenService.get(addAppTokenResponseSlowTest.results.getId())
.setKs(getOperatorKs());
- Response getAppTokenResponse = executor.executeSync(getAppTokenBuilder);
-
- assertThat(getAppTokenResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500055).getCode());
+ int delayBetweenRetriesInSeconds = 10;
+ int maxTimeExpectingValidResponseInSeconds = 150;
+ // test that token expired
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ apiException = executor.executeSync(getAppTokenBuilder).error;
+ return (apiException != null);
+ });
+
+ assertThat(apiException.getCode()).isEqualTo(getAPIExceptionFromList(500055).getCode());
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/add - with no expiry date (return default expiry date -" +
"According to app_token_max_expiry_seconds key value in group_203 CB document")
@Test
@@ -119,9 +141,10 @@ private void addAppTokenWithNoExpiryDate() {
.setKs(getSharedMasterUserKs());
Response addAppTokenResponse = executor.executeSync(addAppTokenBuilder);
- assertThat(addAppTokenResponse.results.getExpiry()).isGreaterThan(Math.toIntExact(BaseUtils.getTimeInEpoch(0)));
+ assertThat(addAppTokenResponse.results.getExpiry()).isGreaterThan(Math.toIntExact(getEpoch()));
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/add - with no specific user id")
@Test
private void addAppTokenWithoutSpecificUserId() {
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenDeleteTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenDeleteTests.java
index 7e32acfc8..df630a693 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenDeleteTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenDeleteTests.java
@@ -1,61 +1,86 @@
package com.kaltura.client.test.tests.servicesTests.appTokenTests;
import com.kaltura.client.enums.AppTokenHashType;
-import com.kaltura.client.services.AppTokenService;
import com.kaltura.client.test.tests.BaseTest;
-import com.kaltura.client.test.utils.AppTokenUtils;
import com.kaltura.client.types.AppToken;
import com.kaltura.client.utils.response.base.Response;
import io.qameta.allure.Description;
-import org.testng.annotations.BeforeClass;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
import org.testng.annotations.Test;
-import static com.kaltura.client.services.AppTokenService.*;
+import static com.kaltura.client.services.AppTokenService.add;
+import static com.kaltura.client.services.AppTokenService.delete;
import static com.kaltura.client.test.tests.BaseTest.SharedHousehold.getSharedUser;
import static com.kaltura.client.test.utils.BaseUtils.getAPIExceptionFromList;
import static org.assertj.core.api.Assertions.assertThat;
public class AppTokenDeleteTests extends BaseTest {
-
- private String sessionUserId;
- private AppToken appToken;
-
- @BeforeClass
- private void add_tests_before_class() {
- sessionUserId = getSharedUser().getUserId();
- appToken = AppTokenUtils.addAppToken(sessionUserId, AppTokenHashType.SHA1, null, null);
- }
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/delete")
@Test
- // TODO: 5/3/2018 not clear test name!
- private void addAppToken() {
+ private void deleteAppToken() {
// Add token
- AddAppTokenBuilder addAppTokenBuilder = AppTokenService.add(appToken).setKs(getOperatorKs());
- Response appTokenResponse = executor.executeSync(addAppTokenBuilder);
+ String sessionUserId = getSharedUser().getUserId();
+
+ AppToken appToken = new AppToken();
+ appToken.setSessionUserId(sessionUserId);
+ appToken.setHashType(AppTokenHashType.SHA1);
+
+ Response appTokenResponse = executor.executeSync(add(appToken)
+ .setKs(getOperatorKs()));
assertThat(appTokenResponse.error).isNull();
assertThat(appTokenResponse.results.getExpiry()).isNull();
// Delete token
- DeleteAppTokenBuilder deleteAppTokenBuilder = AppTokenService.delete(appTokenResponse.results.getId()).setKs(getOperatorKs());
- Response deleteTokenResponse = executor.executeSync(deleteAppTokenBuilder);
+ Response booleanResponse = executor.executeSync(delete(appTokenResponse.results.getId())
+ .setKs(getOperatorKs()));
- assertThat(deleteTokenResponse.results).isTrue();
+ assertThat(booleanResponse.results).isTrue();
+ }
+ @Severity(SeverityLevel.MINOR)
+ @Description("appToken/action/delete - invalid token")
+ @Test
+ private void deleteInvalidAppToken() {
// Try to delete token using invalid token id
String invalidTokenId = "1234";
- deleteAppTokenBuilder = AppTokenService.delete(invalidTokenId).setKs(getOperatorKs());
- deleteTokenResponse = executor.executeSync(deleteAppTokenBuilder);
+ Response booleanResponse = executor.executeSync(delete(invalidTokenId)
+ .setKs(getOperatorKs()));
+
+ assertThat(booleanResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500055).getCode());
+ }
+
+ @Severity(SeverityLevel.MINOR)
+ @Description("appToken/action/delete - same token twice")
+ @Test
+ private void deleteSameAppTokenTwice() {
+ // Add token
+ String sessionUserId = getSharedUser().getUserId();
+
+ AppToken appToken = new AppToken();
+ appToken.setSessionUserId(sessionUserId);
+ appToken.setHashType(AppTokenHashType.SHA1);
+
+ Response appTokenResponse = executor.executeSync(add(appToken)
+ .setKs(getOperatorKs()));
+
+ assertThat(appTokenResponse.error).isNull();
+ assertThat(appTokenResponse.results.getExpiry()).isNull();
+
+ // Delete token
+ Response booleanResponse = executor.executeSync(delete(appTokenResponse.results.getId())
+ .setKs(getOperatorKs()));
- // TODO: 5/3/2018 split two scenarios into separate tests
- assertThat(deleteTokenResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500055).getCode());
+ assertThat(booleanResponse.results).isTrue();
// Try to delete token again - exception returned
- deleteAppTokenBuilder = AppTokenService.delete(appTokenResponse.results.getId()).setKs(getOperatorKs());
- deleteTokenResponse = executor.executeSync(deleteAppTokenBuilder);
+ booleanResponse = executor.executeSync(delete(appTokenResponse.results.getId())
+ .setKs(getOperatorKs()));
- assertThat(deleteTokenResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500055).getCode());
+ assertThat(booleanResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500055).getCode());
}
}
\ No newline at end of file
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenGetTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenGetTests.java
index 37256f284..f1b9249c8 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenGetTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenGetTests.java
@@ -8,9 +8,13 @@
import com.kaltura.client.types.AppToken;
import com.kaltura.client.utils.response.base.Response;
import io.qameta.allure.Description;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import java.util.Calendar;
+
import static com.kaltura.client.test.tests.BaseTest.SharedHousehold.getSharedUser;
import static com.kaltura.client.test.utils.BaseUtils.getAPIExceptionFromList;
import static org.assertj.core.api.Assertions.assertThat;
@@ -28,9 +32,10 @@ public class AppTokenGetTests extends BaseTest {
@BeforeClass
private void get_tests_before_class() {
sessionUserId = getSharedUser().getUserId();
- expiryDate = BaseUtils.getTimeInEpoch(offSetInMinutes);
+ expiryDate = BaseUtils.getEpoch(Calendar.MINUTE, offSetInMinutes);
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("AppToken/action/get")
@Test
private void getAppToken() {
@@ -54,6 +59,7 @@ private void getAppToken() {
assertThat(getAppTokenResponse.results.getSessionUserId()).isEqualTo(sessionUserId);
}
+ @Severity(SeverityLevel.MINOR)
@Description("AppToken/action/get")
@Test
// TODO: 5/3/2018 use underscore in test method names and edit the description
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenStartSessionTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenStartSessionTests.java
index e732aed69..334dafbcc 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenStartSessionTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/appTokenTests/AppTokenStartSessionTests.java
@@ -11,9 +11,13 @@
import com.kaltura.client.utils.response.base.Response;
import io.qameta.allure.Description;
import io.qameta.allure.Issue;
+import io.qameta.allure.Severity;
+import io.qameta.allure.SeverityLevel;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
+import java.util.Calendar;
+
import static com.kaltura.client.services.AppTokenService.StartSessionAppTokenBuilder;
import static com.kaltura.client.services.OttUserService.AnonymousLoginOttUserBuilder;
import static com.kaltura.client.services.OttUserService.anonymousLogin;
@@ -39,9 +43,10 @@ private void add_tests_before_class() {
AnonymousLoginOttUserBuilder anonymousLoginOttUserBuilder = anonymousLogin(partnerId, udid1);
Response loginSessionResponse = executor.executeSync(anonymousLoginOttUserBuilder);
anonymousKs = loginSessionResponse.results.getKs();
- expiryDate = BaseUtils.getTimeInEpoch(1);
+ expiryDate = BaseUtils.getEpoch(Calendar.MINUTE, 1);
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/startSession - SHA1")
@Test
private void startSessionSha1() {
@@ -85,6 +90,7 @@ private void startSessionSha1() {
}
+ @Severity(SeverityLevel.CRITICAL)
@Description("appToken/action/startSession - SHA256")
@Test
private void startSessionSha256() {
@@ -125,9 +131,10 @@ private void startSessionSha256() {
// TODO - Add session/action/get request with ks received from startSession API
}
+ @Severity(SeverityLevel.CRITICAL)
@Issue("BEO-4980")
@Description("appToken/action/startSession - token id with default expiry date (according to the value in group_203 CB document")
- @Test
+ @Test(enabled = false)
private void startSessionDefaultExpiryDate() {
// TODO: 5/3/2018 add comments!
int expiryDate = 0;
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentAddTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentAddTests.java
index d5171614f..6c09f5394 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentAddTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentAddTests.java
@@ -6,19 +6,21 @@
import com.kaltura.client.test.tests.BaseTest;
import com.kaltura.client.test.utils.AssetCommentUtils;
import com.kaltura.client.test.utils.BaseUtils;
-import com.kaltura.client.test.utils.IngestUtils;
import com.kaltura.client.types.*;
import com.kaltura.client.utils.response.base.Response;
import io.qameta.allure.Description;
+import org.assertj.core.data.Offset;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.util.Optional;
+import java.util.List;
import static com.kaltura.client.services.AssetCommentService.AddAssetCommentBuilder;
import static com.kaltura.client.services.AssetCommentService.ListAssetCommentBuilder;
import static com.kaltura.client.test.utils.HouseholdUtils.createHousehold;
import static com.kaltura.client.test.utils.HouseholdUtils.getHouseholdMasterUserKs;
+import static com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils.EpgData;
+import static com.kaltura.client.test.utils.ingestUtils.IngestEpgUtils.insertEpg;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
public class AssetCommentAddTests extends BaseTest {
@@ -37,7 +39,7 @@ private void add_tests_before_class() {
int numOfUsers = 1;
int numOfDevices = 1;
household = createHousehold(numOfUsers, numOfDevices, false);
- householdMasterUserKs = getHouseholdMasterUserKs(household,null);
+ householdMasterUserKs = getHouseholdMasterUserKs(household);
}
@Description("AssetComment/action/add - vod asset")
@@ -50,7 +52,7 @@ private void addCommentForVod() {
// AssetComment/action/add
AddAssetCommentBuilder addAssetCommentBuilder = AssetCommentService.add(assetComment)
- .setKs(getHouseholdMasterUserKs(household,null));
+ .setKs(getHouseholdMasterUserKs(household));
Response assetCommentResponse = executor.executeSync(addAssetCommentBuilder);
//Assertions for AssetComment/action/add
@@ -61,7 +63,7 @@ private void addCommentForVod() {
assertThat(assetCommentResponse.results.getText()).isEqualTo(text);
assertThat(assetCommentResponse.results.getSubHeader()).isEqualTo(subHeader);
assertThat(assetCommentResponse.results.getHeader()).isEqualTo(header);
- assertThat(assetCommentResponse.results.getCreateDate()).isLessThanOrEqualTo(BaseUtils.getTimeInEpoch(0));
+ assertThat(assetCommentResponse.results.getCreateDate()).isCloseTo(BaseUtils.getEpoch(), Offset.offset ((long)10));
//Initialize assetCommentFilter object
@@ -82,18 +84,16 @@ private void addCommentForVod() {
assertThat(assetCommentObjectResponse.getHeader()).isEqualTo(assetCommentResponse.results.getHeader());
assertThat(assetCommentObjectResponse.getText()).isEqualTo(assetCommentResponse.results.getText());
assertThat(assetCommentObjectResponse.getWriter()).isEqualTo(assetCommentResponse.results.getWriter());
- assertThat(assetCommentObjectResponse.getCreateDate()).isLessThanOrEqualTo(BaseUtils.getTimeInEpoch(0));
+ assertThat(assetCommentObjectResponse.getCreateDate()).isCloseTo(BaseUtils.getEpoch(), Offset.offset ((long)10));
}
@Description("AssetComment/action/add - EPG program")
@Test
private void addCommentForEPGProgram() {
-
// Ingest EPG program
- Response> epgProgram = IngestUtils.ingestEPG("Shmulik_Series_1", Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
- Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty());
- Long epgProgramId = epgProgram.results.getObjects().get(0).getId();
+ List epgPrograms = insertEpg(new EpgData("Shmulik_Series_1"));
+ Long epgProgramId = epgPrograms.get(0).getId();
// Initialize assetComment object
AssetComment assetComment = AssetCommentUtils.assetComment(Math.toIntExact(epgProgramId), AssetType.EPG, writer, text, createDate, subHeader, header);
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentListTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentListTests.java
index 434d103e0..67452fc9b 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentListTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetCommentTests/AssetCommentListTests.java
@@ -4,8 +4,8 @@
import com.kaltura.client.enums.AssetType;
import com.kaltura.client.services.AssetCommentService;
import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.MediaType;
import com.kaltura.client.test.utils.AssetCommentUtils;
-import com.kaltura.client.test.utils.IngestUtils;
import com.kaltura.client.types.AssetComment;
import com.kaltura.client.types.AssetCommentFilter;
import com.kaltura.client.types.Household;
@@ -15,12 +15,11 @@
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
-import java.util.Optional;
-
import static com.kaltura.client.services.AssetCommentService.ListAssetCommentBuilder;
-import static com.kaltura.client.test.IngestConstants.MOVIE_MEDIA_TYPE;
import static com.kaltura.client.test.utils.HouseholdUtils.createHousehold;
import static com.kaltura.client.test.utils.HouseholdUtils.getHouseholdMasterUserKs;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.VodData;
+import static com.kaltura.client.test.utils.ingestUtils.IngestVodUtils.insertVod;
import static org.assertj.core.api.Assertions.assertThat;
public class AssetCommentListTests extends BaseTest {
@@ -29,32 +28,30 @@ public class AssetCommentListTests extends BaseTest {
private String householdMasterUserKs;
@BeforeClass
- // TODO: 5/3/2018 edit before method name
- private void add_tests_before_class() {
+ private void asset_comment_listTests_before_class() {
int numOfUsers = 1;
int numOfDevices = 1;
household = createHousehold(numOfUsers, numOfDevices, false);
- householdMasterUserKs = getHouseholdMasterUserKs(household, null);
+ householdMasterUserKs = getHouseholdMasterUserKs(household);
}
@Description("AssetComment/action/list - check order by functionality")
@Test
private void checkCommentsOrder() {
-
String writer = "Shmulik";
Long createDate = 0L;
String header = "header";
String subHeader = "subHeader";
String text = "A lot of text";
- Long assetId = IngestUtils.ingestVOD(Optional.empty(), Optional.empty(), true, Optional.empty(), Optional.empty(), Optional.empty(), Optional.empty(),
- Optional.empty(), Optional.empty(), Optional.empty(), Optional.of(String.valueOf(MOVIE_MEDIA_TYPE)), Optional.empty(), Optional.empty()).getId();
+ VodData vodData = new VodData()
+ .mediaType(MediaType.MOVIE);
+ Long assetId = insertVod(vodData, true).getId();
// Initialize assetComment object
AssetComment assetComment = AssetCommentUtils.assetComment(Math.toIntExact(assetId), AssetType.MEDIA, writer, text, createDate, subHeader, header);
// AssetComment/action/add - first comment
-
AssetCommentService.AddAssetCommentBuilder addAssetCommentBuilder = AssetCommentService.add(assetComment)
.setKs(householdMasterUserKs);
Response assetComment1Response = executor.executeSync(addAssetCommentBuilder);
@@ -69,7 +66,6 @@ private void checkCommentsOrder() {
AssetCommentOrderBy.CREATE_DATE_DESC);
//AssetComment/action/list - return both comments
-
ListAssetCommentBuilder listAssetCommentBuilder = AssetCommentService.list(assetCommentFilter, null)
.setKs(householdMasterUserKs);
Response> assetCommentListResponse = executor.executeSync(listAssetCommentBuilder);
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetHistoryTests/AssetHistoryCleanTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetHistoryTests/AssetHistoryCleanTests.java
new file mode 100644
index 000000000..0752bd9f7
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetHistoryTests/AssetHistoryCleanTests.java
@@ -0,0 +1,412 @@
+package com.kaltura.client.test.tests.servicesTests.assetHistoryTests;
+
+import com.kaltura.client.enums.*;
+import com.kaltura.client.services.HouseholdService;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.utils.AssetUtils;
+import com.kaltura.client.types.*;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Description;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import static com.kaltura.client.services.AssetHistoryService.*;
+import static com.kaltura.client.services.BookmarkService.AddBookmarkBuilder;
+import static com.kaltura.client.services.BookmarkService.add;
+import static com.kaltura.client.test.tests.enums.MediaType.EPISODE;
+import static com.kaltura.client.test.tests.enums.MediaType.MOVIE;
+import static com.kaltura.client.test.utils.AssetUtils.getAssets;
+import static com.kaltura.client.test.utils.BookmarkUtils.addBookmark;
+import static com.kaltura.client.test.utils.HouseholdUtils.*;
+import static com.kaltura.client.test.utils.PurchaseUtils.purchasePpv;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getMediaTypeId;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+public class AssetHistoryCleanTests extends BaseTest {
+
+
+ private final int position1 = 10;
+ private final int position2 = 20;
+ private final int numOfUsers = 1;
+ private final int numOfDevices = 2;
+
+ private MediaAsset movie;
+ private int movieFileId;
+
+ private MediaAsset movie2;
+ private int movie2FileId;
+
+ private MediaAsset episode;
+ private int episodeFileId;
+
+ String masterUserKsCleanHistory;
+ String masterUserKsCleanSpecifcAssetHistory;
+ String masterUserKsCleanSpecifcAssetTypeHistory;
+ String masterUserKsCleanAssetsAccordingToWatchStatusDone;
+ String masterUserKsCleanAssetsAccordingToWatchStatusProgress;
+
+ @BeforeClass(alwaysRun = true)
+ private void assetHistory_clean_tests_before_class() {
+ List movies = getAssets(2, MOVIE);
+
+ // get first movie asset
+ movie = movies.get(0);
+ movieFileId = AssetUtils.getAssetFileIds(String.valueOf(movie.getId())).get(0);
+
+ // get second movie asset
+ movie2 = movies.get(1);
+ movie2FileId = AssetUtils.getAssetFileIds(String.valueOf(movie2.getId())).get(0);
+
+ // Ingest episode asset
+ episode = getAssets(1, EPISODE).get(0);
+ episodeFileId = AssetUtils.getAssetFileIds(String.valueOf(episode.getId())).get(0);
+ }
+
+
+ @Description("assetHistory/action/clean - no filtering")
+ @Test(groups = {"slowBefore"})
+ private void cleanHistory_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsCleanHistory = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsCleanHistory, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanHistory, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark1 = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark1).setKs(masterUserKsCleanHistory);
+ executor.executeSync(addBookmarkBuilder);
+
+ // purchase media2 and prepare media file for playback
+ masterUserKsCleanHistory = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsCleanHistory, Optional.of(movie2.getId().intValue()), Optional.of(movie2FileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanHistory, String.valueOf(movie2.getId()),
+ String.valueOf(movie2FileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark second asset
+ Bookmark bookmark2 = addBookmark(position1, String.valueOf(movie2.getId()), movie2FileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ addBookmarkBuilder = add(bookmark2).setKs(masterUserKsCleanHistory);
+ executor.executeSync(addBookmarkBuilder);
+ }
+
+ @Description("assetHistory/action/clean - no filtering")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void cleanHistory_after_wait() {
+ // assetHistory/action/list - both assets should returned
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 2 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsCleanHistory)).results.getTotalCount() == 2);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsCleanHistory));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(2);
+
+ // assetHistory/action/clean
+ CleanAssetHistoryBuilder cleanAssetHistoryBuilder = clean(assetHistoryFilter);
+ cleanAssetHistoryBuilder.setKs(masterUserKsCleanHistory);
+ executor.executeSync(cleanAssetHistoryBuilder);
+
+ // assetHistory/action/list - after clean - no object returned
+ assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsCleanHistory));
+
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(0);
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsCleanHistory));
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset id")
+ @Test(groups = {"slowBefore"})
+ private void cleanSpecifcAssetHistory_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsCleanSpecifcAssetHistory = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsCleanSpecifcAssetHistory, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanSpecifcAssetHistory, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark1 = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark1)
+ .setKs(masterUserKsCleanSpecifcAssetHistory));
+
+ // purchase media2 and prepare media file for playback
+ masterUserKsCleanSpecifcAssetHistory = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsCleanSpecifcAssetHistory, Optional.of(movie2.getId().intValue()), Optional.of(movie2FileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanSpecifcAssetHistory, String.valueOf(movie2.getId()),
+ String.valueOf(movie2FileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark second asset
+ Bookmark bookmark2 = addBookmark(position2, String.valueOf(movie2.getId()), movie2FileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark2)
+ .setKs(masterUserKsCleanSpecifcAssetHistory));
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset id")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void cleanSpecifcAssetHistory_after_wait() {
+ // assetHistory/action/clean
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setAssetIdIn(String.valueOf(movie.getId()));
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ CleanAssetHistoryBuilder cleanAssetHistoryBuilder = clean(assetHistoryFilter);
+ cleanAssetHistoryBuilder.setKs(masterUserKsCleanSpecifcAssetHistory);
+ executor.executeSync(cleanAssetHistoryBuilder);
+
+ // Update assetHistoryFilter object (assetIdIn = "")
+ assetHistoryFilter.setAssetIdIn("");
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsCleanSpecifcAssetHistory)).results.getTotalCount() == 1);
+ });
+
+ // assetHistory/action/list - after clean - only asset id 2 returned (was not cleaned)
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsCleanSpecifcAssetHistory));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(movie2.getId());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsCleanSpecifcAssetHistory));
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset type")
+ @Test(groups = {"slowBefore"})
+ private void cleanSpecifcAssetTypeHistory_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsCleanSpecifcAssetTypeHistory = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsCleanSpecifcAssetTypeHistory, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanSpecifcAssetTypeHistory, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark)
+ .setKs(masterUserKsCleanSpecifcAssetTypeHistory));
+
+ // purchase media episode and prepare media file for playback
+ masterUserKsCleanSpecifcAssetTypeHistory = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsCleanSpecifcAssetTypeHistory, Optional.of(episode.getId().intValue()), Optional.of(episodeFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanSpecifcAssetTypeHistory, String.valueOf(episode.getId()),
+ String.valueOf(episodeFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark second asset
+ bookmark = addBookmark(position2, String.valueOf(episode.getId()), episodeFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark)
+ .setKs(masterUserKsCleanSpecifcAssetTypeHistory));
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset type")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void cleanSpecifcAssetTypeHistory_after_wait() {
+ //assetHistory/action/clean - only episode type (episode)
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setTypeIn(String.valueOf(getMediaTypeId(EPISODE)));
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ CleanAssetHistoryBuilder cleanAssetHistoryBuilder = clean(assetHistoryFilter);
+ cleanAssetHistoryBuilder.setKs(masterUserKsCleanSpecifcAssetTypeHistory);
+ executor.executeSync(cleanAssetHistoryBuilder);
+
+ // Update assetHistoryFilter object (assetIdIn = "")
+ assetHistoryFilter.setTypeIn("");
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsCleanSpecifcAssetTypeHistory)).results.getTotalCount() == 1);
+ });
+
+ // assetHistory/action/list - after clean - only movie returned (was not cleaned)
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsCleanSpecifcAssetTypeHistory));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(movie.getId());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsCleanSpecifcAssetTypeHistory));
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset finished")
+ @Test(groups = {"slowBefore"})
+ private void cleanAssetsAccordingToWatchStatusDone_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsCleanAssetsAccordingToWatchStatusDone = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsCleanAssetsAccordingToWatchStatusDone, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanAssetsAccordingToWatchStatusDone, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(masterUserKsCleanAssetsAccordingToWatchStatusDone);
+ executor.executeSync(addBookmarkBuilder);
+
+ // purchase media episode and prepare media file for playback
+ masterUserKsCleanAssetsAccordingToWatchStatusDone = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsCleanAssetsAccordingToWatchStatusDone, Optional.of(episode.getId().intValue()), Optional.of(episodeFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanAssetsAccordingToWatchStatusDone, String.valueOf(episode.getId()),
+ String.valueOf(episodeFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark second asset
+ bookmark = addBookmark(position2, String.valueOf(episode.getId()), episodeFileId, AssetType.MEDIA, BookmarkActionType.FINISH);
+ addBookmarkBuilder = add(bookmark).setKs(masterUserKsCleanAssetsAccordingToWatchStatusDone);
+ executor.executeSync(addBookmarkBuilder);
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset finished")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void cleanAssetsAccordingToWatchStatusDone_after_wait() {
+ //assetHistory/action/clean - only asset that were finished (episode)
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setStatusEqual(WatchStatus.DONE);
+
+ CleanAssetHistoryBuilder cleanAssetHistoryBuilder = clean(assetHistoryFilter);
+ cleanAssetHistoryBuilder.setKs(masterUserKsCleanAssetsAccordingToWatchStatusDone);
+ executor.executeSync(cleanAssetHistoryBuilder);
+
+ // assetHistory/action/list - after clean - only movie returned (was not cleaned)
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsCleanAssetsAccordingToWatchStatusDone)).results.getTotalCount() == 1);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsCleanAssetsAccordingToWatchStatusDone));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(movie.getId());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsCleanAssetsAccordingToWatchStatusDone));
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset in progress")
+ @Test(groups = {"slowBefore"})
+ private void cleanAssetsAccordingToWatchStatusProgress_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsCleanAssetsAccordingToWatchStatusProgress = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsCleanAssetsAccordingToWatchStatusProgress, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanAssetsAccordingToWatchStatusProgress, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(masterUserKsCleanAssetsAccordingToWatchStatusProgress);
+ executor.executeSync(addBookmarkBuilder);
+
+ // purchase media2 and prepare media file for playback
+ masterUserKsCleanAssetsAccordingToWatchStatusProgress = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsCleanAssetsAccordingToWatchStatusProgress, Optional.of(episode.getId().intValue()), Optional.of(episodeFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsCleanAssetsAccordingToWatchStatusProgress, String.valueOf(episode.getId()),
+ String.valueOf(episodeFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark second asset
+ bookmark = addBookmark(position2, String.valueOf(episode.getId()), episodeFileId, AssetType.MEDIA, BookmarkActionType.FINISH);
+ addBookmarkBuilder = add(bookmark).setKs(masterUserKsCleanAssetsAccordingToWatchStatusProgress);
+ executor.executeSync(addBookmarkBuilder);
+ }
+
+ @Description("assetHistory/action/clean - filtered by asset in progress")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void cleanAssetsAccordingToWatchStatusProgress_after_wait() {
+ // assetHistory/action/clean - only asset that in progress (movie)
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setStatusEqual(WatchStatus.PROGRESS);
+
+ CleanAssetHistoryBuilder cleanAssetHistoryBuilder = clean(assetHistoryFilter);
+ cleanAssetHistoryBuilder.setKs(masterUserKsCleanAssetsAccordingToWatchStatusProgress);
+ executor.executeSync(cleanAssetHistoryBuilder);
+
+ // assetHistory/action/list - after clean - only episode returned (was not cleaned)
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsCleanAssetsAccordingToWatchStatusProgress)).results.getTotalCount() == 1);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsCleanAssetsAccordingToWatchStatusProgress));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(episode.getId());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsCleanAssetsAccordingToWatchStatusProgress));
+ }
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetHistoryTests/AssetHistoryListTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetHistoryTests/AssetHistoryListTests.java
new file mode 100644
index 000000000..6be9373b0
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetHistoryTests/AssetHistoryListTests.java
@@ -0,0 +1,437 @@
+package com.kaltura.client.test.tests.servicesTests.assetHistoryTests;
+
+import com.kaltura.client.enums.*;
+import com.kaltura.client.services.HouseholdService;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.MediaType;
+import com.kaltura.client.test.utils.AssetUtils;
+import com.kaltura.client.test.utils.BaseUtils;
+import com.kaltura.client.types.*;
+import com.kaltura.client.utils.response.base.Response;
+import io.qameta.allure.Description;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
+
+import static com.kaltura.client.services.AssetHistoryService.list;
+import static com.kaltura.client.services.BookmarkService.AddBookmarkBuilder;
+import static com.kaltura.client.services.BookmarkService.add;
+import static com.kaltura.client.test.tests.enums.MediaType.EPISODE;
+import static com.kaltura.client.test.tests.enums.MediaType.MOVIE;
+import static com.kaltura.client.test.utils.AssetUtils.getAssets;
+import static com.kaltura.client.test.utils.BaseUtils.getConcatenatedString;
+import static com.kaltura.client.test.utils.BookmarkUtils.addBookmark;
+import static com.kaltura.client.test.utils.HouseholdUtils.*;
+import static com.kaltura.client.test.utils.PurchaseUtils.purchasePpv;
+import static com.kaltura.client.test.utils.dbUtils.DBUtils.getMediaTypeId;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
+
+public class AssetHistoryListTests extends BaseTest {
+ private final int position1 = 10;
+ private final int position2 = 20;
+ private final int numOfUsers = 1;
+ private final int numOfDevices = 2;
+
+ private MediaAsset movie;
+ private int movieFileId;
+
+ private MediaAsset movie2;
+ private int movie2FileId;
+
+ private MediaAsset episode;
+ private int episodeFileId;
+
+ private String masterUserKsAssetHistoryTwoMedias;
+ private String masterUserKsAssetHistoryOneMedia;
+ private String masterUserKsVodAssetHistoryFilteredByAssetId;
+ private String masterUserKsVodAssetHistoryFilteredByAssetType;
+ private String masterUserKsVodAssetHistoryFilteredByAssetProgress;
+
+
+ @BeforeClass(alwaysRun = true)
+ private void list_tests_before_class() {
+ List movies = getAssets(2, MOVIE);
+
+ // get first movie asset
+ movie = movies.get(0);
+ movieFileId = AssetUtils.getAssetFileIds(String.valueOf(movie.getId())).get(0);
+
+ // get second movie asset
+ movie2 = movies.get(1);
+ movie2FileId = AssetUtils.getAssetFileIds(String.valueOf(movie2.getId())).get(0);
+
+ // Ingest episode asset
+ episode = getAssets(1, EPISODE).get(0);
+ episodeFileId = AssetUtils.getAssetFileIds(String.valueOf(episode.getId())).get(0);
+ }
+
+ @Description("assetHistory/action/list - with no filter and one device and two media")
+ @Test(groups = {"slowBefore"}, priority = -1)
+ private void assetHistory_vod_with_one_device_and_two_media_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ masterUserKsAssetHistoryTwoMedias = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsAssetHistoryTwoMedias, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsAssetHistoryTwoMedias, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset - first play
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark).setKs(masterUserKsAssetHistoryTwoMedias));
+
+ // Bookmark first asset - stop
+ bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.STOP);
+ executor.executeSync(add(bookmark).setKs(masterUserKsAssetHistoryTwoMedias));
+
+ // purchase media2 and prepare media file for playback
+ purchasePpv(masterUserKsAssetHistoryTwoMedias, Optional.of(movie2.getId().intValue()), Optional.of(movie2FileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsAssetHistoryTwoMedias, String.valueOf(movie2.getId()),
+ String.valueOf(movie2FileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark second asset - first play
+ bookmark = addBookmark(position2, String.valueOf(movie2.getId()), movie2FileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark).setKs(masterUserKsAssetHistoryTwoMedias));
+ }
+
+ @Description("assetHistory/action/list - with no filter and one device and two media")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void assetHistory_vod_with_one_device_and_two_media_after_wait() {
+ // assetHistory/action/list - both assets should returned
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsAssetHistoryTwoMedias)).results.getTotalCount() == 2);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsAssetHistoryTwoMedias));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(2);
+
+ // objects can be returned in any order
+ AssetHistory assetHistoryObject1, assetHistoryObject2;
+ if (assetHistoryListResponse.results.getObjects().get(0).getAssetId().equals(movie2.getId())) {
+ assetHistoryObject1 = assetHistoryListResponse.results.getObjects().get(0);
+ assetHistoryObject2 = assetHistoryListResponse.results.getObjects().get(1);
+ } else {
+ assetHistoryObject1 = assetHistoryListResponse.results.getObjects().get(1);
+ assetHistoryObject2 = assetHistoryListResponse.results.getObjects().get(0);
+ }
+
+ // Assertions for first object returned
+ assertThat(assetHistoryObject1.getAssetType()).isEqualTo(AssetType.MEDIA);
+ assertThat(assetHistoryObject1.getDuration()).isGreaterThan(0);
+ assertThat(assetHistoryObject1.getPosition()).isEqualTo(position2);
+ assertThat(assetHistoryObject1.getAssetId()).isEqualTo(movie2.getId());
+
+ // Verify that flag is set to false (user hasn't finish watching the asset)
+ assertThat(assetHistoryObject1.getFinishedWatching()).isFalse();
+ assertThat(assetHistoryObject1.getWatchedDate()).isLessThanOrEqualTo(BaseUtils.getEpoch());
+
+ // Assertions for second object returned
+ assertThat(assetHistoryObject2.getAssetId()).isEqualTo(movie.getId());
+ assertThat(assetHistoryObject2.getAssetType()).isEqualTo(AssetType.MEDIA);
+ assertThat(assetHistoryObject2.getPosition()).isEqualTo(position1);
+
+ // Assert total count = 2 (two bookmarks)
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(2);
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsAssetHistoryTwoMedias));
+ }
+
+ @Description("assetHistory/action/list - with no filter and two devices and one media")
+ @Test(groups = {"slowBefore"})
+ private void assetHistory_vod_with_two_devices_and_one_media_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsAssetHistoryOneMedia = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback on first device
+ purchasePpv(masterUserKsAssetHistoryOneMedia, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsAssetHistoryOneMedia, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first device - first play
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark).setKs(masterUserKsAssetHistoryOneMedia));
+
+ // prepare media file for playback on second device
+ masterUserKsAssetHistoryOneMedia = getHouseholdMasterUserKs(household, udid2);
+ AssetUtils.playbackAssetFilePreparation(masterUserKsAssetHistoryOneMedia, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark second device - first play
+ bookmark = addBookmark(position2, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ executor.executeSync(add(bookmark).setKs(masterUserKsAssetHistoryOneMedia));
+ }
+
+ @Description("assetHistory/action/list - with no filter and two devices and one media")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void assetHistory_vod_with_two_devices_and_one_media_after_wait() {
+ // assetHistory/action/list - both assets should returned
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsAssetHistoryOneMedia)).results.getTotalCount() == 1);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsAssetHistoryOneMedia));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+
+ AssetHistory assetHistoryObject1 = assetHistoryListResponse.results.getObjects().get(0);
+ assertThat(assetHistoryObject1.getAssetType()).isEqualTo(AssetType.MEDIA);
+ assertThat(assetHistoryObject1.getDuration()).isGreaterThan(0);
+ assertThat(assetHistoryObject1.getPosition()).isEqualTo(position2);
+ assertThat(assetHistoryObject1.getAssetId()).isEqualTo(movie.getId());
+ assertThat(assetHistoryObject1.getFinishedWatching()).isFalse();
+ assertThat(assetHistoryObject1.getWatchedDate()).isLessThanOrEqualTo(BaseUtils.getEpoch());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsAssetHistoryOneMedia));
+ }
+
+ @Description("assetHistory/action/list - filtered by movie asset id")
+ @Test(groups = {"slowBefore"})
+ private void vodAssetHistoryFilteredByAssetId_before_wait() {
+ // create household
+ int numOfDevices = 3;
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ String udid3 = getDevicesList(household).get(2).getUdid();
+ masterUserKsVodAssetHistoryFilteredByAssetId = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsVodAssetHistoryFilteredByAssetId, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsVodAssetHistoryFilteredByAssetId, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(masterUserKsVodAssetHistoryFilteredByAssetId);
+ executor.executeSync(addBookmarkBuilder);
+
+ // purchase media2 and prepare media file for playback
+ masterUserKsVodAssetHistoryFilteredByAssetId = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsVodAssetHistoryFilteredByAssetId, Optional.of(movie2.getId().intValue()), Optional.of(movie2FileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsVodAssetHistoryFilteredByAssetId, String.valueOf(movie2.getId()),
+ String.valueOf(movie2FileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark Second asset
+ bookmark = addBookmark(position2, String.valueOf(movie2.getId()), movie2FileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ addBookmarkBuilder = add(bookmark).setKs(masterUserKsVodAssetHistoryFilteredByAssetId);
+ executor.executeSync(addBookmarkBuilder);
+
+ // purchase media2 and prepare media file for playback
+ masterUserKsVodAssetHistoryFilteredByAssetId = getHouseholdMasterUserKs(household, udid3);
+ purchasePpv(masterUserKsVodAssetHistoryFilteredByAssetId, Optional.of(episode.getId().intValue()), Optional.of(episodeFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsVodAssetHistoryFilteredByAssetId, String.valueOf(episode.getId()),
+ String.valueOf(episodeFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark third asset
+ bookmark = addBookmark(position1, String.valueOf(episode.getId()), episodeFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ addBookmarkBuilder = add(bookmark).setKs(masterUserKsVodAssetHistoryFilteredByAssetId);
+ executor.executeSync(addBookmarkBuilder);
+ }
+
+ @Description("assetHistory/action/list - filtered by movie asset id")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void vodAssetHistoryFilteredByAssetId_after_wait() {
+ //assetHistory/action/list - filter by asset 2 id
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setAssetIdIn(String.valueOf(movie2.getId()));
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsVodAssetHistoryFilteredByAssetId)).results.getTotalCount() == 1);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsVodAssetHistoryFilteredByAssetId));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(movie2.getId());
+
+ //assetHistory/action/list - filter by asset 2 and asset 3 ids
+ String concatenatedString = getConcatenatedString(String.valueOf(movie2.getId()), String.valueOf(episode.getId()));
+ assetHistoryFilter.setAssetIdIn(concatenatedString);
+
+ List assetHistoryList = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsVodAssetHistoryFilteredByAssetId)).results.getObjects();
+
+ assertThat(assetHistoryList).extracting("assetId")
+ .containsExactlyInAnyOrder(movie2.getId(), episode.getId());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsVodAssetHistoryFilteredByAssetId));
+ }
+
+ @Description("assetHistory/action/list - filtered by movie type id")
+ @Test(groups = {"slowBefore"})
+ private void vodAssetHistoryFilteredByAssetType_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsVodAssetHistoryFilteredByAssetType = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsVodAssetHistoryFilteredByAssetType, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsVodAssetHistoryFilteredByAssetType, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(masterUserKsVodAssetHistoryFilteredByAssetType);
+ executor.executeSync(addBookmarkBuilder);
+
+ // purchase media episode and prepare media file for playback
+ masterUserKsVodAssetHistoryFilteredByAssetType = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsVodAssetHistoryFilteredByAssetType, Optional.of(episode.getId().intValue()), Optional.of(episodeFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsVodAssetHistoryFilteredByAssetType, String.valueOf(episode.getId()),
+ String.valueOf(episodeFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark Second asset
+ bookmark = addBookmark(position2, String.valueOf(episode.getId()), episodeFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ addBookmarkBuilder = add(bookmark).setKs(masterUserKsVodAssetHistoryFilteredByAssetType);
+ executor.executeSync(addBookmarkBuilder);
+ }
+
+ @Description("assetHistory/action/list - filtered by movie type id")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void vodAssetHistoryFilteredByAssetType_after_wait() {
+ //assetHistory/action/list - filter by in progress assets only
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setStatusEqual(WatchStatus.ALL);
+ assetHistoryFilter.setTypeIn(String.valueOf(getMediaTypeId(MediaType.MOVIE)));
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsVodAssetHistoryFilteredByAssetType)).results.getTotalCount() == 1);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsVodAssetHistoryFilteredByAssetType));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(movie.getId());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsVodAssetHistoryFilteredByAssetType));
+ }
+
+ @Description("assetHistory/action/list - filtered by assets progress")
+ @Test(groups = {"slowBefore"})
+ private void vodAssetHistoryFilteredByAssetProgress_before_wait() {
+ // create household
+ Household household = createHousehold(numOfUsers, numOfDevices, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String udid2 = getDevicesList(household).get(1).getUdid();
+ masterUserKsVodAssetHistoryFilteredByAssetProgress = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKsVodAssetHistoryFilteredByAssetProgress, Optional.of(movie.getId().intValue()), Optional.of(movieFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsVodAssetHistoryFilteredByAssetProgress, String.valueOf(movie.getId()),
+ String.valueOf(movieFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark first asset
+ Bookmark bookmark = addBookmark(position1, String.valueOf(movie.getId()), movieFileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(masterUserKsVodAssetHistoryFilteredByAssetProgress);
+ executor.executeSync(addBookmarkBuilder);
+
+ // purchase media episode and prepare media file for playback
+ masterUserKsVodAssetHistoryFilteredByAssetProgress = getHouseholdMasterUserKs(household, udid2);
+ purchasePpv(masterUserKsVodAssetHistoryFilteredByAssetProgress, Optional.of(episode.getId().intValue()), Optional.of(episodeFileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKsVodAssetHistoryFilteredByAssetProgress, String.valueOf(episode.getId()),
+ String.valueOf(episodeFileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
+ // Bookmark Second asset
+ bookmark = addBookmark(position2, String.valueOf(episode.getId()), episodeFileId, AssetType.MEDIA, BookmarkActionType.FINISH);
+ addBookmarkBuilder = add(bookmark).setKs(masterUserKsVodAssetHistoryFilteredByAssetProgress);
+ executor.executeSync(addBookmarkBuilder);
+ }
+
+ @Description("assetHistory/action/list - filtered by assets progress")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void vodAssetHistoryFilteredByAssetProgress_after_wait() {
+ //assetHistory/action/list - filter by in progress assets only
+ AssetHistoryFilter assetHistoryFilter = new AssetHistoryFilter();
+ assetHistoryFilter.setStatusEqual(WatchStatus.PROGRESS);
+
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() -> {
+ // wait for 1 assets at history response
+ return (executor.executeSync(list(assetHistoryFilter).setKs(masterUserKsVodAssetHistoryFilteredByAssetProgress)).results.getTotalCount() == 1);
+ });
+
+ Response> assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsVodAssetHistoryFilteredByAssetProgress));
+
+ assertThat(assetHistoryListResponse.error).isNull();
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(movie.getId());
+
+ //assetHistory/action/list - filter by finished assets only
+ assetHistoryFilter.setStatusEqual(WatchStatus.DONE);
+
+ assetHistoryListResponse = executor.executeSync(list(assetHistoryFilter)
+ .setKs(masterUserKsVodAssetHistoryFilteredByAssetProgress));
+
+ assertThat(assetHistoryListResponse.results.getTotalCount()).isEqualTo(1);
+ assertThat(assetHistoryListResponse.results.getObjects().get(0).getAssetId()).isEqualTo(episode.getId());
+
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKsVodAssetHistoryFilteredByAssetProgress));
+ }
+ //todo - Currently EPG program not returned in response (Ticket was opened to Omer - BEO-4594]
+}
\ No newline at end of file
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetRuleTests/AssetRuleDeleteTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetRuleTests/AssetRuleDeleteTests.java
new file mode 100644
index 000000000..aff6e656e
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetRuleTests/AssetRuleDeleteTests.java
@@ -0,0 +1,17 @@
+package com.kaltura.client.test.tests.servicesTests.assetRuleTests;
+
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.utils.AssetRuleUtils;
+import io.qameta.allure.Description;
+import org.testng.annotations.Test;
+
+public class AssetRuleDeleteTests extends BaseTest {
+
+
+ @Description("/assetrule/action/delete - currently used to run util only")
+ @Test(enabled = false) // as test is not implemented yet
+ private void deleteAllGeoAssetRules() {
+ AssetRuleUtils.deleteAllGeoAssetRules();
+ }
+
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/assetStatisticsTests/AssetStatisticsQueryTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetStatisticsTests/AssetStatisticsQueryTests.java
new file mode 100644
index 000000000..b629c5783
--- /dev/null
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/assetStatisticsTests/AssetStatisticsQueryTests.java
@@ -0,0 +1,48 @@
+package com.kaltura.client.test.tests.servicesTests.assetStatisticsTests;
+
+import com.kaltura.client.enums.AssetType;
+import com.kaltura.client.services.AssetStatisticsService.QueryAssetStatisticsBuilder;
+import com.kaltura.client.test.tests.BaseTest;
+import com.kaltura.client.test.tests.enums.MediaType;
+import com.kaltura.client.test.utils.AssetUtils;
+import com.kaltura.client.types.AssetStatistics;
+import com.kaltura.client.types.AssetStatisticsQuery;
+import com.kaltura.client.types.ListResponse;
+import com.kaltura.client.types.MediaAsset;
+import com.kaltura.client.utils.response.base.Response;
+import org.testng.annotations.BeforeClass;
+import org.testng.annotations.Test;
+
+import java.util.List;
+
+import static com.kaltura.client.services.AssetStatisticsService.query;
+
+public class AssetStatisticsQueryTests extends BaseTest{
+
+ private MediaAsset media1;
+ private MediaAsset media2;
+ private MediaAsset media3;
+
+ @BeforeClass(enabled = false)
+ private void assetStatistics_before_class(){
+ List medias = AssetUtils.getAssets(3, MediaType.MOVIE);
+ media1 = medias.get(0);
+ media2 = medias.get(1);
+ media3 = medias.get(2);
+ }
+
+ @Test(enabled = false)
+ public void asset(){
+
+ AssetStatisticsQuery assetStatisticsQuery = new AssetStatisticsQuery();
+ assetStatisticsQuery.setAssetIdIn(String.valueOf(media1.getId()));
+ assetStatisticsQuery.setAssetTypeEqual(AssetType.MEDIA);
+
+ QueryAssetStatisticsBuilder queryAssetStatisticsBuilder = query(assetStatisticsQuery);
+ Response> assetStatistics = executor.executeSync(queryAssetStatisticsBuilder);
+
+
+ }
+
+
+}
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkAddTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkAddTests.java
index 294466672..cda95feb2 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkAddTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkAddTests.java
@@ -1,11 +1,14 @@
package com.kaltura.client.test.tests.servicesTests.bookmarkTests;
import com.kaltura.client.enums.*;
-import com.kaltura.client.services.BookmarkService;
+import com.kaltura.client.services.HouseholdService;
import com.kaltura.client.test.tests.BaseTest;
import com.kaltura.client.test.utils.AssetUtils;
import com.kaltura.client.test.utils.BookmarkUtils;
-import com.kaltura.client.types.*;
+import com.kaltura.client.types.Bookmark;
+import com.kaltura.client.types.BookmarkFilter;
+import com.kaltura.client.types.Household;
+import com.kaltura.client.types.ListResponse;
import com.kaltura.client.utils.response.base.Response;
import io.qameta.allure.Description;
import org.testng.annotations.BeforeClass;
@@ -13,29 +16,30 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import static com.kaltura.client.services.BookmarkService.*;
-import static com.kaltura.client.test.tests.BaseTest.SharedHousehold.*;
+import static com.kaltura.client.test.tests.BaseTest.SharedHousehold.getSharedMasterUserKs;
import static com.kaltura.client.test.utils.BaseUtils.getAPIExceptionFromList;
+import static com.kaltura.client.test.utils.HouseholdUtils.*;
+import static com.kaltura.client.test.utils.PurchaseUtils.purchasePpv;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
public class BookmarkAddTests extends BaseTest {
private long assetId;
private int fileId;
- private BookmarkActionType actionType;
+ private List assetList;
+ private Bookmark bookmark;
+ private BookmarkFilter bookmarkFilter;
private int position;
- private List assetList = new ArrayList<>();
- // instantiate Bookmark object
- private Bookmark bookmark = new Bookmark();
- // instantiate BookmarkFilter object
- private BookmarkFilter bookmarkFilter = new BookmarkFilter();
- @BeforeClass
- private void add_tests_before_class() {
-
- getSharedHousehold();
+ @BeforeClass(alwaysRun = true)
+ private void bookmark_addTests_before_class() {
+ assetList = new ArrayList<>();
assetId = BaseTest.getSharedMediaAsset().getId();
fileId = AssetUtils.getAssetFileIds(String.valueOf(assetId)).get(0);
@@ -46,27 +50,37 @@ private void add_tests_before_class() {
}
@Description("bookmark/action/add - first play")
- @Test
- private void firstPlayback() {
- actionType = BookmarkActionType.FIRST_PLAY;
+ @Test(groups = {"slowBefore"})
+ private void firstPlayback_before_wait() {
position = 0;
- bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, actionType);
+
+ bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
// Invoke bookmark/action/add request
- AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark);
- addBookmarkBuilder.setKs(getSharedMasterUserKs());
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(getSharedMasterUserKs());
Response booleanResponse = executor.executeSync(addBookmarkBuilder);
- // Verify response return true
assertThat(booleanResponse.results.booleanValue()).isTrue();
- // Verify no error returned
assertThat(booleanResponse.error).isNull();
-
+ }
+ @Description("bookmark/action/add - first play")
+ @Test(groups = {"slowAfter"}, dependsOnGroups = {"slowBefore"}, alwaysRun = true)
+ private void firstPlayback_after_wait() {
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
// Invoke bookmark/action/list to verify insertion of bookmark position
- ListBookmarkBuilder listBookmarkBuilder = BookmarkService.list(bookmarkFilter);
- listBookmarkBuilder.setKs(getSharedMasterUserKs());
+ ListBookmarkBuilder listBookmarkBuilder = list(bookmarkFilter).setKs(getSharedMasterUserKs());
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() ->{
+ return (executor.executeSync(listBookmarkBuilder).results.getTotalCount() != 0);
+ });
+
Response> bookmarkListResponse = executor.executeSync(listBookmarkBuilder);
+ assertThat(bookmarkListResponse.error).isNull();
Bookmark bookmark1 = bookmarkListResponse.results.getObjects().get(0);
@@ -74,7 +88,7 @@ private void firstPlayback() {
assertThat(bookmark1.getId()).isEqualTo(String.valueOf(assetId));
// Match content of asset position
- assertThat(bookmark1.getPosition()).isEqualTo(this.position);
+ assertThat(bookmark1.getPosition()).isEqualTo(position);
// verify finishedWatching = false
assertThat(bookmark1.getFinishedWatching()).isFalse();
@@ -87,125 +101,184 @@ private void firstPlayback() {
// Verify total count = 1
assertThat(bookmarkListResponse.results.getTotalCount()).isEqualTo(1);
-
}
@Description("bookmark/action/add - pause")
- @Test
- private void pausePlayback() {
- // Set action type to "PAUSE"
- actionType = BookmarkActionType.PAUSE;
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"firstPlayback_after_wait"}, alwaysRun=true)
+ private void pausePlayback_before_wait() {
position = 30;
- bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, actionType);
+ bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, BookmarkActionType.PAUSE);
// Invoke bookmark/action/add request
- AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark);
- addBookmarkBuilder.setKs(getSharedMasterUserKs());
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(getSharedMasterUserKs());
Response booleanResponse = executor.executeSync(addBookmarkBuilder);
- // Verify response return true
assertThat(booleanResponse.results.booleanValue()).isTrue();
- // Verify no error returned
assertThat(booleanResponse.error).isNull();
+ }
+
+ @Description("bookmark/action/add - pause")
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"pausePlayback_before_wait"}, alwaysRun = true)
+ private void pausePlayback_after_wait() {
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
// Invoke bookmark/action/list to verify insertion of bookmark position
- ListBookmarkBuilder listBookmarkBuilder = BookmarkService.list(bookmarkFilter);
- listBookmarkBuilder.setKs(getSharedMasterUserKs());
+ ListBookmarkBuilder listBookmarkBuilder = list(bookmarkFilter).setKs(getSharedMasterUserKs());
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() ->{
+ return (executor.executeSync(listBookmarkBuilder).results.getObjects().get(0).getPosition() == position);
+ });
+
Response> bookmarkListResponse = executor.executeSync(listBookmarkBuilder);
+ assertThat(bookmarkListResponse.error).isNull();
Bookmark bookmark = bookmarkListResponse.results.getObjects().get(0);
// Match content of asset position
- assertThat(bookmark.getPosition()).isEqualTo(this.position);
+ assertThat(bookmark.getPosition()).isEqualTo(position);
}
@Description("bookmark/action/add - 95% watching == finish watching")
- @Test
- private void watchingNinetyFive() {
- actionType = BookmarkActionType.PLAY;
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"pausePlayback_after_wait"}, alwaysRun=true)
+ private void watchingNinetyFive_before_wait() {
position = 999;
- bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, actionType);
+ bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, BookmarkActionType.PLAY);
// Invoke bookmark/action/add request
- AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark);
- addBookmarkBuilder.setKs(getSharedMasterUserKs());
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(getSharedMasterUserKs());
Response booleanResponse = executor.executeSync(addBookmarkBuilder);
- // Verify response return true
+
assertThat(booleanResponse.results.booleanValue()).isTrue();
- // Verify no error returned
assertThat(booleanResponse.error).isNull();
+ }
+
+ @Description("bookmark/action/add - 95% watching == finish watching")
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"watchingNinetyFive_before_wait"}, alwaysRun = true)
+ private void watchingNinetyFive_after_wait() {
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
// Invoke bookmark/action/list to verify insertion of bookmark position
- ListBookmarkBuilder listBookmarkBuilder = BookmarkService.list(bookmarkFilter);
- listBookmarkBuilder.setKs(getSharedMasterUserKs());
+ ListBookmarkBuilder listBookmarkBuilder = list(bookmarkFilter).setKs(getSharedMasterUserKs());
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() ->{
+ return (executor.executeSync(listBookmarkBuilder).results.getObjects().get(0).getPosition() == position);
+ });
+
Response> bookmarkListResponse = executor.executeSync(listBookmarkBuilder);
+ assertThat(bookmarkListResponse.error).isNull();
Bookmark bookmark3 = bookmarkListResponse.results.getObjects().get(0);
// Verify finishedWatching = true
assertThat(bookmark3.getFinishedWatching()).isTrue();
-
}
@Description("bookmark/action/add - back to start - position:0")
- @Test
- private void backToStart() {
- actionType = BookmarkActionType.STOP;
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"watchingNinetyFive_after_wait"}, alwaysRun=true)
+ private void backToStart_before_wait() {
position = 0;
- bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, actionType);
+ bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, BookmarkActionType.STOP);
- AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark);
- addBookmarkBuilder.setKs(getSharedMasterUserKs());
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(getSharedMasterUserKs());
Response booleanResponse = executor.executeSync(addBookmarkBuilder);
assertThat(booleanResponse.results.booleanValue()).isTrue();
- ListBookmarkBuilder listBookmarkBuilder = BookmarkService.list(bookmarkFilter);
- listBookmarkBuilder.setKs(getSharedMasterUserKs());
+ assertThat(booleanResponse.error).isNull();
+ }
+
+ @Description("bookmark/action/add - back to start - position:0")
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"backToStart_before_wait"}, alwaysRun = true)
+ private void backToStart_after_wait() {
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
+
+ // Invoke bookmark/action/list to verify insertion of bookmark position
+ ListBookmarkBuilder listBookmarkBuilder = list(bookmarkFilter).setKs(getSharedMasterUserKs());
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() ->{
+ return (executor.executeSync(listBookmarkBuilder).results.getObjects().get(0).getPosition() == position);
+ });
+
Response> bookmarkListResponse = executor.executeSync(listBookmarkBuilder);
+ assertThat(bookmarkListResponse.error).isNull();
Bookmark bookmark = bookmarkListResponse.results.getObjects().get(0);
+
// Verify finishedWatching = false
assertThat(bookmark.getFinishedWatching()).isFalse();
}
@Description("bookmark/action/add - finish watching")
- @Test
- private void finishWatching() {
- // Set action type to "FINISH"
- actionType = BookmarkActionType.FINISH;
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"backToStart_after_wait"}, alwaysRun=true)
+ private void finishWatching_before_wait() {
position = 60;
- bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, actionType);
+ bookmark = BookmarkUtils.addBookmark(position, String.valueOf(assetId), fileId, AssetType.MEDIA, BookmarkActionType.FINISH);
// Invoke bookmark/action/add request
- AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark);
- addBookmarkBuilder.setKs(getSharedMasterUserKs());
- Response booleanResponse = executor.executeSync(addBookmarkBuilder);
- // Verify response return true
+ Response booleanResponse = executor.executeSync(add(bookmark)
+ .setKs(getSharedMasterUserKs()));
+
assertThat(booleanResponse.results.booleanValue()).isTrue();
- // Verify no error returned
assertThat(booleanResponse.error).isNull();
+ }
+
+ @Description("bookmark/action/add - finish watching")
+ @Test(groups = {"slowAfter"}, dependsOnMethods = {"finishWatching_before_wait"}, alwaysRun = true)
+ private void finishWatching_after_wait() {
+ // prepare variables for await() functionality
+ int delayBetweenRetriesInSeconds = 15;
+ int maxTimeExpectingValidResponseInSeconds = 80;
// Invoke bookmark/action/list to verify insertion of bookmark position
- ListBookmarkBuilder listBookmarkBuilder = BookmarkService.list(bookmarkFilter);
- listBookmarkBuilder.setKs(getSharedMasterUserKs());
+ ListBookmarkBuilder listBookmarkBuilder = list(bookmarkFilter).setKs(getSharedMasterUserKs());
+ await()
+ .pollInterval(delayBetweenRetriesInSeconds, TimeUnit.SECONDS)
+ .atMost(maxTimeExpectingValidResponseInSeconds, TimeUnit.SECONDS)
+ .until(() ->{
+ return (executor.executeSync(listBookmarkBuilder).results.getObjects().get(0).getFinishedWatching().equals(true));
+ });
+
Response> bookmarkListResponse = executor.executeSync(listBookmarkBuilder);
+ assertThat(bookmarkListResponse.error).isNull();
Bookmark bookmark = bookmarkListResponse.results.getObjects().get(0);
- // Verify finishedWatching = true
- assertThat(bookmark.getFinishedWatching()).isTrue();
-
+ // Verify postion = 0
+ assertThat(bookmark.getPosition()).isEqualTo(0);
}
- // Error validations
-
@Description("bookmark/action/add - empty asset id")
- @Test
+ @Test(enabled = false)
private void emptyAssetId() {
+ // create household
+ int numberOfUsersInHousehold = 1;
+ int numberOfDevicesInHousehold = 1;
+ Household household = createHousehold(numberOfUsersInHousehold, numberOfDevicesInHousehold, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ String masterUserKs = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKs, Optional.of((int)assetId), Optional.of(fileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKs, String.valueOf(assetId),
+ String.valueOf(fileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
bookmark = BookmarkUtils.addBookmark(0, null, fileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
- AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark);
- addBookmarkBuilder.setKs(getSharedMasterUserKs());
+ AddBookmarkBuilder addBookmarkBuilder = add(bookmark).setKs(masterUserKs);
Response booleanResponse = executor.executeSync(addBookmarkBuilder);
+
assertThat(booleanResponse.results).isNull();
// Verify exception returned - code: 500003 ("Invalid Asset id")
assertThat(booleanResponse.error.getCode()).isEqualTo(getAPIExceptionFromList(500003).getCode());
- }
+ // cleanup - delete household
+ executor.executeSync(HouseholdService.delete().setKs(masterUserKs));
+ }
// TODO - Add test for EPG bookmark
// TODO - Add test for recording bookmark
diff --git a/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkListTests.java b/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkListTests.java
index ba818af51..8001675cd 100644
--- a/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkListTests.java
+++ b/src/test/java/com/kaltura/client/test/tests/servicesTests/bookmarkTests/BookmarkListTests.java
@@ -1,14 +1,13 @@
package com.kaltura.client.test.tests.servicesTests.bookmarkTests;
-import com.kaltura.client.enums.AssetType;
-import com.kaltura.client.enums.BookmarkActionType;
-import com.kaltura.client.enums.BookmarkOrderBy;
+import com.kaltura.client.enums.*;
import com.kaltura.client.services.BookmarkService;
import com.kaltura.client.test.tests.BaseTest;
import com.kaltura.client.test.utils.AssetUtils;
import com.kaltura.client.test.utils.BookmarkUtils;
import com.kaltura.client.types.Bookmark;
import com.kaltura.client.types.BookmarkFilter;
+import com.kaltura.client.types.Household;
import com.kaltura.client.types.ListResponse;
import com.kaltura.client.utils.response.base.Response;
import io.qameta.allure.Description;
@@ -17,24 +16,27 @@
import java.util.ArrayList;
import java.util.List;
+import java.util.Optional;
+import java.util.concurrent.TimeUnit;
import static com.kaltura.client.services.BookmarkService.*;
import static com.kaltura.client.test.tests.BaseTest.SharedHousehold.getSharedMasterUserKs;
+import static com.kaltura.client.test.utils.BaseUtils.getAPIExceptionFromList;
+import static com.kaltura.client.test.utils.HouseholdUtils.*;
+import static com.kaltura.client.test.utils.PurchaseUtils.purchasePpv;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.awaitility.Awaitility.await;
public class BookmarkListTests extends BaseTest {
- private Long assetId;
- private int fileId;
+ private long assetId, assetId2;
+ private int fileId, fileId2;
+ private List assetList;
+ private String masterUserKs;
-
- private Long assetId2;
- private int fileId2;
-
- private List assetList = new ArrayList<>();
-
- @BeforeClass
- private void list_tests_before_class() {
+ @BeforeClass(alwaysRun = true)
+ private void bookmark_listTests_before_class() {
+ assetList = new ArrayList<>();
assetId = BaseTest.getSharedMediaAsset().getId();
List assetFileIds = AssetUtils.getAssetFileIds(String.valueOf(assetId));
@@ -48,31 +50,66 @@ private void list_tests_before_class() {
}
@Description("bookmark/action/list - order by")
- @Test
-
- private void BookmarkOrderBy() {
+ @Test(groups = {"slowBefore"})
+ private void BookmarkOrderBy_before_wait() {
+ // create household
+ int numberOfUsersInHousehold = 1;
+ int numberOfDevicesInHousehold = 1;
+ Household household = createHousehold(numberOfUsersInHousehold, numberOfDevicesInHousehold, true);
+ String udid1 = getDevicesList(household).get(0).getUdid();
+ masterUserKs = getHouseholdMasterUserKs(household, udid1);
+
+ // purchase media and prepare media file for playback
+ purchasePpv(masterUserKs, Optional.of((int)assetId), Optional.of(fileId), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKs, String.valueOf(assetId),
+ String.valueOf(fileId), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
// Bookmark asset1
Bookmark bookmark = BookmarkUtils.addBookmark(0, String.valueOf(assetId), fileId, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
- BookmarkService.AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark);
- addBookmarkBuilder.setKs(getSharedMasterUserKs());
+ BookmarkService.AddBookmarkBuilder addBookmarkBuilder = BookmarkService.add(bookmark).setKs(masterUserKs);
Response booleanResponse = executor.executeSync(addBookmarkBuilder);
+ assertThat(booleanResponse.error).isNull();
assertThat(booleanResponse.results.booleanValue()).isTrue();
+ // purchase media2 and prepare media file for playback
+ purchasePpv(masterUserKs, Optional.of((int)assetId2), Optional.of(fileId2), Optional.empty());
+ AssetUtils.playbackAssetFilePreparation(masterUserKs, String.valueOf(assetId2),
+ String.valueOf(fileId2), AssetType.MEDIA, PlaybackContextType.PLAYBACK, UrlType.PLAYMANIFEST);
+
// Bookmark asset2
Bookmark bookmark2 = BookmarkUtils.addBookmark(10, String.valueOf(assetId2), fileId2, AssetType.MEDIA, BookmarkActionType.FIRST_PLAY);
- AddBookmarkBuilder addBookmarkBuilder2 = BookmarkService.add(bookmark2);
- addBookmarkBuilder2.setKs(getSharedMasterUserKs());
+ AddBookmarkBuilder addBookmarkBuilder2 = BookmarkService.add(bookmark2).setKs(masterUserKs);
Response