PlanStore { public IDField addPlan(String planName, String description, String logicalPlanJson) throws TexeraException { if (planName == null || description == null || logicalPlanJson == null) { throw new TexeraException("Arguments cannot be null when adding a plan"); } if (!PlanStoreConstants.VALID_PLAN_NAME.matcher(planName).find()) { throw new TexeraException("Plan name is not valid. It can only contain alphanumeric characters, " + "underscore, and hyphen."); } if (getPlan(planName) != null) { throw new TexeraException("A plan with the same name already exists"); } try { ObjectMapper objectMapper = new ObjectMapper(); JsonNode jsonNode = objectMapper.readValue(logicalPlanJson, JsonNode.class); logicalPlanJson = objectMapper.writeValueAsString(jsonNode); } catch (IOException e) { throw new StorageException("logical plan json is an invalid json string: " + logicalPlanJson); } Tuple tuple = new Tuple(PlanStoreConstants.SCHEMA_PLAN, new StringField(planName), new StringField(description), new StringField(logicalPlanJson)); DataWriter dataWriter = relationManager.getTableDataWriter(PlanStoreConstants.TABLE_NAME); dataWriter.open(); IDField id = dataWriter.insertTuple(tuple); dataWriter.close(); return id; } private  PlanStore(); synchronized static PlanStore getInstance(); void createPlanStore(); void destroyPlanStore(); IDField addPlan(String planName, String description, String logicalPlanJson); Tuple getPlan(String planName); DataReader getPlanIterator(); void deletePlan(String planName); void updatePlanDescription(String planName, String description); void updatePlan(String planName, String logicalPlanJson); void updatePlan(String planName, String description, String logicalPlanJson);  }
@Test public void testAddPlan() throws TexeraException { String planName = "plan"; planStore.addPlan(planName, "basic dictionary source plan", logicalPlanJson1); assertCorrectPlanExists(planName, logicalPlanJson1); }
@Test(expected = TexeraException.class) public void testAddPlanWithInvalidName() throws TexeraException { String planName = "plan/regex"; planStore.addPlan(planName, "basic dictionary source plan", logicalPlanJson1); }
@Test(expected = TexeraException.class) public void testAddPlanWithEmptyName() throws TexeraException { String planName = ""; planStore.addPlan(planName, "basic dictionary source plan", logicalPlanJson1); }
@Test(expected = TexeraException.class) public void testAddMultiplePlansWithSameName() throws TexeraException { String planName = "plan"; planStore.addPlan(planName, "basic dictionary source plan", logicalPlanJson1); planStore.addPlan(planName, "basic keyword source plan", logicalPlanJson2); }