Skip to content

Commit

Permalink
code cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
AnkitCLI committed Mar 18, 2024
1 parent 07881ea commit 1493856
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1301,28 +1301,28 @@ public static void createBucketWithLifeCycle() throws IOException, URISyntaxExce
gcsTargetBucketName = createGCSBucketLifeCycle();
BeforeActions.scenario.write("GCS target bucket name - " + gcsTargetBucketName); }

@Before(order=1, value = "@DATASTORE_SOURCE_ENTITY")
@Before(order = 1, value = "@DATASTORE_SOURCE_ENTITY")
public static void createEntityInCloudDataStore() throws IOException, URISyntaxException {
kindName= "cdf-test-"+ UUID.randomUUID().toString().substring(0, 8);
String EntityName = DataStoreClient.createKind(kindName);
PluginPropertyUtils.addPluginProp(" kindName", EntityName);
BeforeActions.scenario.write("Kind name - " + EntityName + "created successfully");
kindName = "cdf-test-" + UUID.randomUUID().toString().substring(0, 8);
String entityName = DataStoreClient.createKind(kindName);
PluginPropertyUtils.addPluginProp(" kindName", entityName);
BeforeActions.scenario.write("Kind name - " + entityName + "created successfully");
}

@After(order=1, value = "@DATASTORE_SOURCE_ENTITY")
@After(order = 1, value = "@DATASTORE_SOURCE_ENTITY")
public static void deleteEntityInCloudDataStore() throws IOException, URISyntaxException {
DataStoreClient.deleteEntity(kindName);
BeforeActions.scenario.write("Kind name - " + kindName + "deleted successfully");
}

@Before(order = 2, value = "@DATASTORE_TARGET_ENTITY")
public static void setTempTargetKindName() {
targetKind = "cdf-target-test-"+ UUID.randomUUID().toString().substring(0, 8);
targetKind = "cdf-target-test-" + UUID.randomUUID().toString().substring(0, 8);
PluginPropertyUtils.addPluginProp("targetKind", targetKind);
BeforeActions.scenario.write("Target kind name - " + targetKind);
}

@After(order=1, value = "@DATASTORE_TARGET_ENTITY")
@After(order = 1, value = "@DATASTORE_TARGET_ENTITY")
public static void deleteTargetEntityInCloudDataStore() throws IOException, URISyntaxException {
DataStoreClient.deleteEntity(targetKind);
BeforeActions.scenario.write("Target Kind name - " + targetKind + "deleted successfully");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,27 @@
* the License.
*/

package io.cdap.plugin.datastore.stepsdesign.Actions;
package io.cdap.plugin.datastore.actions;

import io.cdap.e2e.utils.ElementHelper;
import io.cdap.e2e.utils.SeleniumHelper;
import io.cdap.plugin.datastore.stepsdesign.Locators.DataStoreLocators;
import io.cdap.plugin.datastore.locators.DataStoreLocators;
import io.cdap.plugin.utils.DataStoreClient;

/**
* DataStore Plugin related actions.
*/
public class DataStoreActions {
static {

SeleniumHelper.getPropertiesLocators(DataStoreLocators.class);
}

public static void enterKind(String kindName) {
ElementHelper.sendKeys(DataStoreLocators.kind, kindName);
}

public static void enterAncestor()
{
public static void enterAncestor() {
ElementHelper.sendKeys(DataStoreLocators.ancestor, DataStoreClient.getKeyLiteral());
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Package contains the actions for the DataStore features.
*/
package io.cdap.plugin.datastore.stepsdesign.Actions;
package io.cdap.plugin.datastore.actions;
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@
* the License.
*/

package io.cdap.plugin.datastore.stepsdesign.Locators;
package io.cdap.plugin.datastore.locators;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.How;

/**
* DataStore Plugin related step design.
*/
public class DataStoreLocators {
@FindBy(how = How.XPATH, using = "//input[@data-testid='kind']")
public static WebElement kind;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Package contains the locators for the DataStore features.
*/
package io.cdap.plugin.datastore.stepsdesign.Locators;
package io.cdap.plugin.datastore.locators;
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
* the License.
*/

package io.cdap.plugin.datastore.stepsdesign.Stepdesigns;
package io.cdap.plugin.datastore.stepsdesign;
import io.cdap.plugin.common.stepsdesign.TestSetupHooks;

import io.cdap.plugin.datastore.stepsdesign.Actions.DataStoreActions;
import io.cdap.plugin.datastore.actions.DataStoreActions;
import io.cucumber.java.en.Then;

public class StepDesigns {
/**
* DataStore Plugin related step design.
*/
public class StepDesign {
@Then("Enter kind for datastore plugin")
public void enterKindForDatastorePlugin() {
DataStoreActions.enterKind(TestSetupHooks.kindName);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/**
* Package contains the stepDesign for the DataStore features.
*/
package io.cdap.plugin.datastore.stepsdesign.Stepdesigns;
package io.cdap.plugin.datastore.stepsdesign;
48 changes: 25 additions & 23 deletions src/e2e-test/java/io/cdap/plugin/utils/DataStoreClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

import java.util.Date;

/**
* Represents DataStore client.
*/
public class DataStoreClient {
private static final Logger logger = LoggerFactory.getLogger(PubSubClient.class);
static Datastore datastore = DatastoreOptions.getDefaultInstance().getService();
Expand Down Expand Up @@ -42,7 +45,7 @@ public static String createKind(String kindName) {
// Save the entity
Entity savedEntity = datastore.put(entity);
key = savedEntity.getKey();
logger.info("Entity saved with key: " + key);
logger.info("Entity saved with key: " + key);

return kindName;
}
Expand All @@ -52,34 +55,33 @@ public static String createKind(String kindName) {
*
* @param kindName the kind name of the entities to be deleted
*/
public static void deleteEntity(String kindName) {
Query<Entity> query = Query.newEntityQueryBuilder()
.setKind(kindName)
.build();
// Execute the query
QueryResults<Entity> queryResults = datastore.run(query);
// Delete each entity
while (queryResults.hasNext()) {
Entity entity = queryResults.next();
Key entityKey = entity.getKey();
datastore.delete(entityKey);
logger.info("Entity deleted: " + entityKey);
}

logger.info("All entities of kind '" + kindName + "' deleted successfully.");
public static void deleteEntity(String kindName) {
Query<Entity> query = Query.newEntityQueryBuilder()
.setKind(kindName)
.build();
// Execute the query
QueryResults<Entity> queryResults = datastore.run(query);
// Delete each entity
while (queryResults.hasNext()) {
Entity entity = queryResults.next();
Key entityKey = entity.getKey();
datastore.delete(entityKey);
logger.info("Entity deleted: " + entityKey);
}

logger.info("All entities of kind '" + kindName + "' deleted successfully.");
}

/**
* Returns the key-literal representation of the current entity key.
*
* @return the key-literal representation of the current entity key
*/
public static String getKeyLiteral()
{
String kind = key.getKind(); // Get the kind of the entity
long id = key.getId(); // Get the ID of the entity
String keyLiteral = String.format("Key(%s, %d)", kind, id);
public static String getKeyLiteral() {
String kind = key.getKind(); // Get the kind of the entity
long id = key.getId(); // Get the ID of the entity
String keyLiteral = String.format("Key(%s, %d)", kind, id);

return keyLiteral;
}
return keyLiteral;
}
}

0 comments on commit 1493856

Please sign in to comment.