method2testcases
stringlengths 118
6.63k
|
---|
### Question:
DeltaJournal implements InitializingBean { public static String getEntityId(Map<String, Object> deltaRecord) { Object deltaId = deltaRecord.get("_id"); if(deltaId instanceof String){ return (String) deltaId; } else if (deltaId instanceof byte[]) { StringBuilder id = new StringBuilder(""); @SuppressWarnings("unchecked") List<byte[]> parts = (List<byte[]>) deltaRecord.get("i"); if (parts != null) { for (byte[] part : parts) { id.insert(0, Hex.encodeHexString(part) + "_id"); } } id.append(Hex.encodeHexString((byte[]) deltaId) + "_id"); return id.toString(); } else { throw new IllegalArgumentException("Illegal id: " + deltaId); } } @Override void afterPropertiesSet(); void journal(Collection<String> ids, String collection, boolean isDelete); static List<byte[]> getByteId(String id); static String getEntityId(Map<String, Object> deltaRecord); void journal(String id, String collection, boolean isDelete); void journalCollapsedSubDocs(Collection<String> ids, String collection); void journalPurge(long timeOfPurge); Iterator<Map<String, Object>> findDeltaRecordBetween(final long start, final long end); void removeDeltaJournals(String tenant, long cleanUptoTime); static final String DELTA_COLLECTION; static final String PURGE; }### Answer:
@Test public void testGetEntityId() throws DecoderException { String id = "1234567890123456789012345678901234567890"; String superid = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"; String extraid = "bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"; Map<String, Object> delta = new HashMap<String, Object>(); delta.put("_id", Hex.decodeHex(id.toCharArray())); assertEquals(id + "_id", DeltaJournal.getEntityId(delta)); delta.put("i", Arrays.asList(Hex.decodeHex(superid.toCharArray()))); assertEquals(superid + "_id" + id + "_id", DeltaJournal.getEntityId(delta)); delta.put("i", Arrays.asList(Hex.decodeHex(superid.toCharArray()), Hex.decodeHex(extraid.toCharArray()))); assertEquals(extraid + "_id" + superid + "_id" + id + "_id", DeltaJournal.getEntityId(delta)); } |
### Question:
StudentAssessmentConverter extends GenericSuperdocConverter implements SuperdocConverter { @Override public Entity subdocToBodyField(Entity entity) { if (entity != null && entity.getType().equals(STUDENT_ASSESSMENT)) { if (entity.getBody() == null || entity.getBody().isEmpty()) { return null; } Entity assessment = retrieveAssessment(entity.getBody().get(ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_ASSESSMENT_ITEM, ASSESSMENT_ITEM_ID, ASSESSMENT_ITEM); subdocsToBody(entity, STUDENT_ASSESSMENT_ITEM, "studentAssessmentItems", Arrays.asList(STUDENT_ASSESSMENT_ID)); referenceEntityResolve(entity, assessment, STUDENT_OBJECTIVE_ASSESSMENT, OBJECTIVE_ASSESSMENT_ID, OBJECTIVE_ASSESSMENT); subdocsToBody(entity, STUDENT_OBJECTIVE_ASSESSMENT, "studentObjectiveAssessments", Arrays.asList(STUDENT_ASSESSMENT_ID)); entity.getEmbeddedData().clear(); } return entity; } @Override Entity subdocToBodyField(Entity entity); @Override void bodyFieldToSubdoc(Entity entity); @Override void bodyFieldToSubdoc(Entity entity, SuperdocConverter.Option option); @Override Iterable<Entity> subdocToBodyField(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities, SuperdocConverter.Option option); }### Answer:
@Test public void upconvertNoAssessmentShouldRemoveInvalidReference() { List<Entity> old = Arrays.asList(createUpConvertEntity()); assertNotNull(old.get(0).getEmbeddedData().get("studentAssessmentItem")); Iterable<Entity> entity = saConverter.subdocToBodyField(old); assertNull(entity.iterator().next().getEmbeddedData().get("studentAssessmentItem")); }
@SuppressWarnings("unchecked") @Test public void testUpConvertShouldCollapseAssessmentItem() { Entity saEntity = createUpConvertEntity(); saEntity.getBody().put("assessmentId", "assessmentId"); saEntity.getBody().put("studentId", "studentId"); List<Entity> old = Arrays.asList(saEntity); assertNull("studentAssessmentItem should not be in body", old.get(0).getBody() .get("studentAssessmentItem")); Entity assessment = createAssessment(); when(repo.getTemplate()).thenReturn(template); when(template.findById("assessmentId", Entity.class, EntityNames.ASSESSMENT)).thenReturn(assessment); Iterable<Entity> entities = saConverter.subdocToBodyField(old); assertNotNull("studentAssessmentItem should be moved into body", entities.iterator().next().getBody().get("studentAssessmentItems")); assertNotNull( "assessmentItem should be collapsed into the studentAssessmentItem", ((List<Map<String, Object>>) (entities.iterator().next().getBody().get("studentAssessmentItems"))).get(0).get( "assessmentItem")); Map<String, Object> assessmentItemBody = (Map<String, Object>) ((List<Map<String, Object>>) (entities.iterator().next() .getBody().get("studentAssessmentItems"))).get(0).get("assessmentItem"); assertEquals("collapsed assessmentItem should have assessmentId field is assessmentId", "assessmentId", assessmentItemBody.get("assessmentId")); assertEquals("collapsed assessmentItem should have identificationCode field is code1", "code1", assessmentItemBody.get("identificationCode")); assertEquals("collapsed assessmentItem should have itemCategory is Matching", "Matching", assessmentItemBody.get("itemCategory")); } |
### Question:
StudentAssessmentConverter extends GenericSuperdocConverter implements SuperdocConverter { @Override public void bodyFieldToSubdoc(Entity entity) { bodyFieldToSubdoc(entity, null); } @Override Entity subdocToBodyField(Entity entity); @Override void bodyFieldToSubdoc(Entity entity); @Override void bodyFieldToSubdoc(Entity entity, SuperdocConverter.Option option); @Override Iterable<Entity> subdocToBodyField(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities); @Override void bodyFieldToSubdoc(Iterable<Entity> entities, SuperdocConverter.Option option); }### Answer:
@Test public void testBodyFieldToSubdoc() { List<Entity> entities = Arrays.asList(createDownConvertEntity()); assertNotNull("studentAssessment body should have studentAssessmentItem", entities.get(0).getBody().get("studentAssessmentItems")); assertNull("studentAssessmentItem should not be outside the studentAssessment body", entities.get(0) .getEmbeddedData().get("studentAssessmentItem")); saConverter.bodyFieldToSubdoc(entities); assertNull("studentAssessment body should not have studentAssessmentItem", entities.get(0).getBody().get("studentAssessmentItems")); assertNotNull("studentAssessmentItem should be moved outside body", entities.get(0).getEmbeddedData().get("studentAssessmentItem")); }
@SuppressWarnings("unchecked") @Test public void testSubdocDid() { List<Entity> entities = Arrays.asList(createDownConvertEntity()); assertNull( "studentAssessmentItem should not have id before transformation", ((List<Map<String, Object>>) (entities.get(0).getBody().get("studentAssessmentItems"))).get(0).get( "_id")); saConverter.bodyFieldToSubdoc(entities); assertFalse("subdoc id should be generated", entities.get(0).getEmbeddedData().get("studentAssessmentItem") .get(0).getEntityId().isEmpty()); } |
### Question:
ContainerDocumentAccessor { public boolean isContainerDocument(final String entity) { return containerDocumentHolder.isContainerDocument(entity); } ContainerDocumentAccessor(final UUIDGeneratorStrategy strategy, final INaturalKeyExtractor extractor,
final MongoTemplate mongoTemplate, final SchemaRepository schemaRepo); boolean isContainerDocument(final String entity); boolean isContainerSubdoc(final String entity); boolean insert(final List<Entity> entityList); String insert(final Entity entity); boolean update(final String type, final String id, Map<String, Object> newValues, String collectionName); String update(final Entity entity); Entity findById(String collectionName, String id); List<Entity> findAll(String collectionName, Query query); boolean delete(final Entity entity); @SuppressWarnings("unchecked") boolean deleteContainerNonSubDocs(final Entity containerDoc); long count(String collectionName, Query query); boolean exists(String collectionName, String id); String getEmbeddedDocType(final String containerDocType); }### Answer:
@Test public void testIsContainerDocument() { when(mockHolder.isContainerDocument(ATTENDANCE)).thenReturn(true); boolean actual = testAccessor.isContainerDocument(ATTENDANCE); assertEquals(true, actual); } |
### Question:
ContainerDocumentAccessor { public boolean isContainerSubdoc(final String entity) { boolean isContainerSubdoc = false; if (containerDocumentHolder.isContainerDocument(entity)) { isContainerSubdoc = containerDocumentHolder.getContainerDocument(entity).isContainerSubdoc(); } return isContainerSubdoc; } ContainerDocumentAccessor(final UUIDGeneratorStrategy strategy, final INaturalKeyExtractor extractor,
final MongoTemplate mongoTemplate, final SchemaRepository schemaRepo); boolean isContainerDocument(final String entity); boolean isContainerSubdoc(final String entity); boolean insert(final List<Entity> entityList); String insert(final Entity entity); boolean update(final String type, final String id, Map<String, Object> newValues, String collectionName); String update(final Entity entity); Entity findById(String collectionName, String id); List<Entity> findAll(String collectionName, Query query); boolean delete(final Entity entity); @SuppressWarnings("unchecked") boolean deleteContainerNonSubDocs(final Entity containerDoc); long count(String collectionName, Query query); boolean exists(String collectionName, String id); String getEmbeddedDocType(final String containerDocType); }### Answer:
@Test public void isContainerSubDoc() { final ContainerDocument cDoc2 = createContainerDocGrade(); when(mockHolder.isContainerDocument(ATTENDANCE)).thenReturn(true); when(mockHolder.isContainerDocument(GRADE)).thenReturn(true); when(mockHolder.getContainerDocument(GRADE)).thenReturn(cDoc2); assertFalse(testAccessor.isContainerSubdoc(ATTENDANCE)); assertTrue(testAccessor.isContainerSubdoc(GRADE)); } |
### Question:
ContainerDocumentAccessor { public boolean insert(final List<Entity> entityList) { boolean result = true; for (Entity entity : entityList) { result &= !insert(entity).isEmpty(); } return result; } ContainerDocumentAccessor(final UUIDGeneratorStrategy strategy, final INaturalKeyExtractor extractor,
final MongoTemplate mongoTemplate, final SchemaRepository schemaRepo); boolean isContainerDocument(final String entity); boolean isContainerSubdoc(final String entity); boolean insert(final List<Entity> entityList); String insert(final Entity entity); boolean update(final String type, final String id, Map<String, Object> newValues, String collectionName); String update(final Entity entity); Entity findById(String collectionName, String id); List<Entity> findAll(String collectionName, Query query); boolean delete(final Entity entity); @SuppressWarnings("unchecked") boolean deleteContainerNonSubDocs(final Entity containerDoc); long count(String collectionName, Query query); boolean exists(String collectionName, String id); String getEmbeddedDocType(final String containerDocType); }### Answer:
@Test public void testInsert() { DBObject query = Mockito.mock(DBObject.class); DBObject docToPersist = ContainerDocumentHelper.buildDocumentToPersist(mockHolder, entity, generatorStrategy, naturalKeyExtractor); when(query.get("_id")).thenReturn(ID); when(mockHolder.getContainerDocument(ATTENDANCE)).thenReturn(createContainerDocAttendance()); when(mongoTemplate.getCollection(ATTENDANCE)).thenReturn(mockCollection); when(mockCollection.update(Mockito.any(DBObject.class), Mockito.eq(docToPersist), Mockito.eq(true), Mockito.eq(false), Mockito.eq(WriteConcern.SAFE))).thenReturn(writeResult); String result = testAccessor.insertContainerDoc(query, entity); assertTrue(result.equals(ID)); assertFalse("Wrong result returned by insert", result.equals("")); Mockito.verify(mockCollection, Mockito.times(1)).update(Mockito.any(DBObject.class), Mockito.eq(docToPersist), Mockito.eq(true), Mockito.eq(false), Mockito.eq(WriteConcern.SAFE)); } |
### Question:
FileEntryWorkNote extends WorkNote implements Serializable { public IngestionFileEntry getFileEntry() { return fileEntry; } FileEntryWorkNote(String batchJobId, IngestionFileEntry fileEntry, boolean hasErrors); IngestionFileEntry getFileEntry(); @Override int hashCode(); @Override boolean equals(Object obj); @Override String toString(); }### Answer:
@Test public void testCreateSimpleWorkNote() { FileEntryWorkNote workNote = new FileEntryWorkNote("batchJobId", null, false); Assert.assertEquals("batchJobId", workNote.getBatchJobId()); Assert.assertEquals(null, workNote.getFileEntry()); } |
### Question:
EntityWriteConverter implements Converter<Entity, DBObject> { @Override public DBObject convert(Entity e) { MongoEntity me; if (e instanceof MongoEntity) { me = (MongoEntity) e; } else { me = new MongoEntity(e.getType(), e.getEntityId(), e.getBody(), e.getMetaData(), e.getCalculatedValues(), e.getAggregates()); } if (encrypt != null) { me.encrypt(encrypt); } return me.toDBObject(uuidGeneratorStrategy, naturalKeyExtractor); } @Override DBObject convert(Entity e); }### Answer:
@Test public void testEntityConvert() throws NoNaturalKeysDefinedException { Entity e = Mockito.mock(Entity.class); HashMap<String, Object> body = new HashMap<String, Object>(); body.put("field1", "field1"); body.put("field2", "field2"); HashMap<String, Object> meta = new HashMap<String, Object>(); meta.put("meta1", "field1"); meta.put("meta2", "field2"); NaturalKeyDescriptor desc = new NaturalKeyDescriptor(); Mockito.when(e.getType()).thenReturn("collection"); Mockito.when(e.getBody()).thenReturn(body); Mockito.when(e.getMetaData()).thenReturn(meta); Mockito.when(naturalKeyExtractor.getNaturalKeyDescriptor(Mockito.any(Entity.class))).thenReturn(desc); Mockito.when(uuidGeneratorStrategy.generateId(desc)).thenReturn("uid"); DBObject d = converter.convert(e); Assert.assertNotNull("DBObject should not be null", d); assertSame(body, (Map<?, ?>) d.get("body")); assertSame(meta, (Map<?, ?>) d.get("metaData")); Assert.assertEquals(1, encryptCalls.size()); Assert.assertEquals(2, encryptCalls.get(0).length); Assert.assertEquals(e.getType(), encryptCalls.get(0)[0]); Assert.assertEquals(e.getBody(), encryptCalls.get(0)[1]); }
@Test public void testMockMongoEntityConvert() { MongoEntity e = Mockito.mock(MongoEntity.class); DBObject result = Mockito.mock(DBObject.class); Mockito.when(e.toDBObject(uuidGeneratorStrategy, naturalKeyExtractor)).thenReturn(result); DBObject d = converter.convert(e); Assert.assertNotNull(d); Assert.assertEquals(result, d); Mockito.verify(e, Mockito.times(1)).encrypt(encryptor); Mockito.verify(e, Mockito.times(1)).toDBObject(uuidGeneratorStrategy, naturalKeyExtractor); }
@Test public void testMongoEntityConvert() { HashMap<String, Object> body = new HashMap<String, Object>(); body.put("field1", "field1"); body.put("field2", "field2"); HashMap<String, Object> meta = new HashMap<String, Object>(); meta.put("meta1", "field1"); meta.put("meta2", "field2"); MongoEntity e = new MongoEntity("collection", UUID.randomUUID().toString(), body, meta); DBObject d = converter.convert(e); Assert.assertNotNull(d); assertSame(body, (Map<?, ?>) d.get("body")); assertSame(meta, (Map<?, ?>) d.get("metaData")); Assert.assertEquals(1, encryptCalls.size()); Assert.assertEquals(2, encryptCalls.get(0).length); Assert.assertEquals(e.getType(), encryptCalls.get(0)[0]); Assert.assertEquals(e.getBody(), encryptCalls.get(0)[1]); } |
### Question:
MongoEntityTemplate extends MongoTemplate { public <T> Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName) { MongoPersistentEntity<?> entity = mappingContext.getPersistentEntity(entityClass); DBCollection collection = getDb().getCollection(collectionName); prepareCollection(collection); DBObject dbQuery = mapper.getMappedObject(query.getQueryObject(), entity); final DBCursor cursor; if (query.getFieldsObject() == null) { cursor = collection.find(dbQuery); } else { cursor = collection.find(dbQuery, query.getFieldsObject()); } return new Iterator<T>() { @Override public boolean hasNext() { return cursor.hasNext(); } @Override public T next() { return getConverter().read(entityClass, cursor.next()); } @Override public void remove() { cursor.remove(); } }; } MongoEntityTemplate(MongoDbFactory mongoDbFactory, MongoConverter mongoConverter); Iterator<T> findEach(final Query query, final Class<T> entityClass, String collectionName); }### Answer:
@Test public void testReadPreference() { template.setReadPreference(ReadPreference.secondary()); Query query = new Query(); template.findEach(query, Entity.class, "student"); Assert.assertEquals(ReadPreference.secondary(), template.getCollection("student").getReadPreference()); } |
### Question:
AesCipher implements org.slc.sli.dal.encrypt.Cipher { @Override public String encrypt(Object data) { if (data instanceof String) { return "ESTRING:" + encryptFromBytes(StringUtils.getBytesUtf8((String) data)); } else { ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(byteOutputStream); String type; try { if (data instanceof Boolean) { dos.writeBoolean((Boolean) data); type = "EBOOL:"; } else if (data instanceof Integer) { dos.writeInt((Integer) data); type = "EINT:"; } else if (data instanceof Long) { dos.writeLong((Long) data); type = "ELONG:"; } else if (data instanceof Double) { dos.writeDouble((Double) data); type = "EDOUBLE:"; } else { throw new RuntimeException("Unsupported type: " + data.getClass().getCanonicalName()); } dos.flush(); dos.close(); } catch (IOException e) { throw new RuntimeException(e); } byte[] bytes = byteOutputStream.toByteArray(); return type + encryptFromBytes(bytes); } } @Override String encrypt(Object data); @Override Object decrypt(String data); }### Answer:
@Test(expected = RuntimeException.class) public void testUnhandled() { aes.encrypt(1.1F); } |
### Question:
AesCipher implements org.slc.sli.dal.encrypt.Cipher { @Override public Object decrypt(String data) { String[] splitData = org.apache.commons.lang3.StringUtils.split(data, ':'); if (splitData.length != 2) { return null; } else { if (splitData[0].equals("ESTRING")) { return StringUtils.newStringUtf8(decryptToBytes(splitData[1])); } else if (splitData[0].equals("EBOOL")) { return decryptBinary(splitData[1], Boolean.class); } else if (splitData[0].equals("EINT")) { return decryptBinary(splitData[1], Integer.class); } else if (splitData[0].equals("ELONG")) { return decryptBinary(splitData[1], Long.class); } else if (splitData[0].equals("EDOUBLE")) { return decryptBinary(splitData[1], Double.class); } else { return null; } } } @Override String encrypt(Object data); @Override Object decrypt(String data); }### Answer:
@Test() public void testUnencryptedString() { Object decrypted = aes.decrypt("Some text"); assertEquals(null, decrypted); Object d2 = aes.decrypt("SOME DATA WITH : IN IT"); assertEquals(null, d2); } |
### Question:
TenantMongoDA implements TenantDA { @Override public String getTenantId(String lzPath) { return findTenantIdByLzPath(lzPath); } @Override List<String> getLzPaths(); @Override String getTenantId(String lzPath); @Override void insertTenant(TenantRecord tenant); @Override @SuppressWarnings("unchecked") String getTenantEdOrg(String lzPath); Repository<Entity> getEntityRepository(); void setEntityRepository(Repository<Entity> entityRepository); @SuppressWarnings("unchecked") @Override Map<String, List<String>> getPreloadFiles(String ingestionServer); @Override boolean tenantDbIsReady(String tenantId); @Override void setTenantReadyFlag(String tenantId); @Override void unsetTenantReadyFlag(String tenantId); @Override boolean updateAndAquireOnboardingLock(String tenantId); @Override void removeInvalidTenant(String lzPath); @Override Map<String, List<String>> getPreloadFiles(); @Override List<String> getAllTenantDbs(); static final String TENANT_ID; static final String DB_NAME; static final String INGESTION_SERVER; static final String PATH; static final String LANDING_ZONE; static final String PRELOAD_DATA; static final String PRELOAD_STATUS; static final String PRELOAD_FILES; static final String TENANT_COLLECTION; static final String TENANT_TYPE; static final String EDUCATION_ORGANIZATION; static final String DESC; static final String ALL_STATUS_FIELDS; static final String STATUS_FIELD; }### Answer:
@Test public void shouldGetTenantIdFromLzPath() { Entity tenantRecord = createTenantEntity(); when(mockRepository.findOne(Mockito.eq("tenant"), Mockito.any(NeutralQuery.class))).thenReturn(tenantRecord); String tenantIdResult = tenantDA.getTenantId(lzPath1); assertNotNull("tenantIdResult was null", tenantIdResult); assertEquals("tenantIdResult did not match expected value", tenantId, tenantIdResult); Mockito.verify(mockRepository, Mockito.times(1)).findOne(Mockito.eq("tenant"), Mockito.any(NeutralQuery.class)); } |
### Question:
UserEdOrgManagerImpl extends ApiClientManager implements UserEdOrgManager { @Override @CacheableUserData public EdOrgKey getUserEdOrg(String token) { GenericEntity edOrg = null; if (!isEducator()) { String id = getApiClient().getId(token); GenericEntity staff = getApiClient().getStaffWithEducationOrganization(token, id, null); if (staff != null) { GenericEntity staffEdOrg = (GenericEntity) staff.get(Constants.ATTR_ED_ORG); if (staffEdOrg != null) { @SuppressWarnings("unchecked") List<String> edOrgCategories = (List<String>) staffEdOrg.get(Constants.ATTR_ORG_CATEGORIES); if (edOrgCategories != null && !edOrgCategories.isEmpty()) { for (String edOrgCategory : edOrgCategories) { if (edOrgCategory.equals(Constants.STATE_EDUCATION_AGENCY)) { edOrg = staffEdOrg; break; } else if (edOrgCategory.equals(Constants.LOCAL_EDUCATION_AGENCY)) { edOrg = staffEdOrg; break; } } } } } } if (edOrg == null) { List<GenericEntity> schools = getMySchools(token); if (schools != null && !schools.isEmpty()) { GenericEntity school = schools.get(0); edOrg = getParentEducationalOrganization(getToken(), school); if (edOrg == null) { throw new DashboardException( "No data is available for you to view. Please contact your IT administrator."); } } } if (edOrg != null) { return new EdOrgKey(edOrg.getId()); } return null; } @Override @CacheableUserData EdOrgKey getUserEdOrg(String token); @Override @CacheableUserData GenericEntity getUserInstHierarchy(String token, Object key, Data config); @Override GenericEntity getUserCoursesAndSections(String token, Object schoolIdObj, Data config); @Override @SuppressWarnings("unchecked") GenericEntity getUserSectionList(String token, Object schoolIdObj, Data config); @Override GenericEntity getStaffInfo(String token); @Override @SuppressWarnings("unchecked") GenericEntity getSchoolInfo(String token, Object schoolIdObj, Data config); }### Answer:
@Test public void testGetUserEdOrg() { this.testInstitutionalHierarchyManagerImpl = new UserEdOrgManagerImpl() { @Override public String getToken() { return ""; } @Override protected boolean isEducator() { return false; } }; this.testInstitutionalHierarchyManagerImpl.setApiClient(apiClient); EdOrgKey edOrgKey1 = this.testInstitutionalHierarchyManagerImpl.getUserEdOrg(Constants.STATE_EDUCATION_AGENCY); Assert.assertEquals("2012ny-09327920-e000-11e1-9f3b-3c07546832b4", edOrgKey1.getSliId()); EdOrgKey edOrgKey2 = this.testInstitutionalHierarchyManagerImpl.getUserEdOrg(Constants.LOCAL_EDUCATION_AGENCY); Assert.assertEquals("2012zj-0b0711a4-e000-11e1-9f3b-3c07546832b4", edOrgKey2.getSliId()); this.testInstitutionalHierarchyManagerImpl = new UserEdOrgManagerImpl() { @Override public String getToken() { return ""; } @Override protected boolean isEducator() { return true; } }; this.testInstitutionalHierarchyManagerImpl.setApiClient(apiClient); EdOrgKey edOrgKey3 = this.testInstitutionalHierarchyManagerImpl.getUserEdOrg("Teacher"); Assert.assertEquals("2012zj-0b0711a4-e000-11e1-9f3b-3c07546832b4", edOrgKey3.getSliId()); } |
### Question:
JsonConverter { public static String toJson(Object o) { return GSON.toJson(o); } static String toJson(Object o); static T fromJson(String json, Class<T> clazz); static T fromJson(Reader reader, Class<T> clazz); }### Answer:
@Test public void test() { GenericEntity entity = new GenericEntity(); GenericEntity element = new GenericEntity(); element.put("tire", "Yokohama"); entity.put("car", element); assertEquals("{\"car\":{\"tire\":\"Yokohama\"}}", JsonConverter.toJson(entity)); } |
### Question:
ParentsSorter { public static List<GenericEntity> sort(List<GenericEntity> genericEntities) { for (GenericEntity genericEntity : genericEntities) { List<Map<String, Object>> studentParentAssociations = (List<Map<String, Object>>) genericEntity .get(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); if (studentParentAssociations != null && !studentParentAssociations.isEmpty()) { Map<String, Object> studentParentAssociation = studentParentAssociations.get(0); genericEntity.put(Constants.ATTR_RELATION, studentParentAssociation.get(Constants.ATTR_RELATION)); genericEntity.put(Constants.ATTR_CONTACT_PRIORITY, studentParentAssociation.get(Constants.ATTR_CONTACT_PRIORITY)); genericEntity.put(Constants.ATTR_PRIMARY_CONTACT_STATUS, studentParentAssociation.get(Constants.ATTR_PRIMARY_CONTACT_STATUS)); } } GenericEntityComparator comparator = new GenericEntityComparator(Constants.ATTR_RELATION, String.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_RELATION, relationPriority); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_CONTACT_PRIORITY, Double.class); Collections.sort(genericEntities, comparator); comparator = new GenericEntityComparator(Constants.ATTR_PRIMARY_CONTACT_STATUS, primaryContactStatusPriority); Collections.sort(genericEntities, comparator); for (GenericEntity genericEntity : genericEntities) { genericEntity.remove(Constants.ATTR_RELATION); genericEntity.remove(Constants.ATTR_CONTACT_PRIORITY); genericEntity.remove(Constants.ATTR_PRIMARY_CONTACT_STATUS); } return genericEntities; } private ParentsSorter(); static List<GenericEntity> sort(List<GenericEntity> genericEntities); }### Answer:
@Test public void testSort() { List<GenericEntity> entities = new LinkedList<GenericEntity>(); List<LinkedHashMap<String, Object>> studentParentsAssocistion = new LinkedList<LinkedHashMap<String, Object>>(); LinkedHashMap<String, Object> obj = new LinkedHashMap<String, Object>(); obj.put(Constants.ATTR_RELATION, "Father"); studentParentsAssocistion.add(obj); GenericEntity entity = new GenericEntity(); entity.put(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS, studentParentsAssocistion); entities.add(entity); obj = new LinkedHashMap<String, Object>(); obj.put(Constants.ATTR_RELATION, "Mother"); studentParentsAssocistion = new LinkedList<LinkedHashMap<String, Object>>(); studentParentsAssocistion.add(obj); entity = new GenericEntity(); entity.put(Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS, studentParentsAssocistion); entities.add(entity); ParentsSorter.sort(entities); List<LinkedHashMap<String, Object>> objTest = (List<LinkedHashMap<String, Object>>) entities.get(0).get( Constants.ATTR_STUDENT_PARENT_ASSOCIATIONS); Assert.assertEquals("Mother", objTest.get(0).get(Constants.ATTR_RELATION)); } |
### Question:
SLIAuthenticationEntryPoint implements AuthenticationEntryPoint { static boolean isSecureRequest(HttpServletRequest request) { String serverName = request.getServerName(); boolean isSecureEnvironment = (!serverName.substring(0, serverName.indexOf(".")).equals( NONSECURE_ENVIRONMENT_NAME)); return (request.isSecure() && isSecureEnvironment); } void setCallbackUrl(String callbackUrl); String getCallbackUrl(); void setApiUrl(String apiUrl); String getApiUrl(); RESTClient getRestClient(); void setRestClient(RESTClient restClient); APIClient getApiClient(); void setApiClient(APIClient apiClient); PropertiesDecryptor getPropDecryptor(); void setPropDecryptor(PropertiesDecryptor propDecryptor); @Override void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException); static final String OAUTH_TOKEN; static final String DASHBOARD_COOKIE; }### Answer:
@Test public void testIsSecuredRequest() throws Exception { LOG.debug("[SLCAuthenticationEntryPointTest]Secure Protocol with local environment, return FALSE"); when(request.getServerName()).thenReturn("local.slidev.org"); when(request.isSecure()).thenReturn(true); assertFalse(SLIAuthenticationEntryPoint.isSecureRequest(request)); LOG.debug("[SLCAuthenticationEntryPointTest]Non-Secure Protocol with local environment, return FALSE"); when(request.getServerName()).thenReturn("local.slidev.org"); when(request.isSecure()).thenReturn(false); assertFalse(SLIAuthenticationEntryPoint.isSecureRequest(request)); LOG.debug("[SLCAuthenticationEntryPointTest]Non-Secure Protocol with non-local environment, return FALSE"); when(request.getServerName()).thenReturn("rcdashboard.slidev.org"); when(request.isSecure()).thenReturn(false); assertFalse(SLIAuthenticationEntryPoint.isSecureRequest(request)); LOG.debug("[SLCAuthenticationEntryPointTest]Non-Secure Protocol with local environment, return FALSE"); when(request.getServerName()).thenReturn("local.slidev.org"); when(request.isSecure()).thenReturn(false); assertFalse(SLIAuthenticationEntryPoint.isSecureRequest(request)); LOG.debug("[SLCAuthenticationEntryPointTest]Non-Secure Protocol with non-local environment, return FALSE"); when(request.getServerName()).thenReturn("rcdashboard.slidev.org"); when(request.isSecure()).thenReturn(false); assertFalse(SLIAuthenticationEntryPoint.isSecureRequest(request)); LOG.debug("[SLCAuthenticationEntryPointTest]Secure Protocol with non-local environment, return TRUE"); when(request.getServerName()).thenReturn("rcdashboard.slidev.org"); when(request.isSecure()).thenReturn(true); assertTrue(SLIAuthenticationEntryPoint.isSecureRequest(request)); } |
### Question:
SLIAuthenticationEntryPoint implements AuthenticationEntryPoint { @Override public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException { HttpSession session = request.getSession(); try { SliApi.setBaseUrl(apiUrl); OAuthService service = new ServiceBuilder().provider(SliApi.class) .apiKey(propDecryptor.getDecryptedClientId()).apiSecret(propDecryptor.getDecryptedClientSecret()) .callback(callbackUrl).build(); boolean cookieFound = checkCookiesForToken(request, session); Object token = session.getAttribute(OAUTH_TOKEN); if (token == null && request.getParameter(OAUTH_CODE) == null) { initiatingAuthentication(request, response, session, service); } else if (token == null && request.getParameter(OAUTH_CODE) != null) { verifyingAuthentication(request, response, session, service); } else { completeAuthentication(request, response, session, token, cookieFound); } } catch (OAuthException ex) { session.invalidate(); LOG.error(LOG_MESSAGE_AUTH_EXCEPTION, new Object[] { ex.getMessage() }); response.sendError(HttpServletResponse.SC_FORBIDDEN, ex.getMessage()); return; } } void setCallbackUrl(String callbackUrl); String getCallbackUrl(); void setApiUrl(String apiUrl); String getApiUrl(); RESTClient getRestClient(); void setRestClient(RESTClient restClient); APIClient getApiClient(); void setApiClient(APIClient apiClient); PropertiesDecryptor getPropDecryptor(); void setPropDecryptor(PropertiesDecryptor propDecryptor); @Override void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException); static final String OAUTH_TOKEN; static final String DASHBOARD_COOKIE; }### Answer:
@Test public void testCommence() throws Exception { HttpSession mockSession = mock(HttpSession.class); AuthenticationException mockAuthenticationException = mock(AuthenticationException.class); PropertiesDecryptor mockPropertiesDecryptor = mock(PropertiesDecryptor.class); APIClient mockAPIClient = mock(APIClient.class); RESTClient mockRESTClient = mock(RESTClient.class); JsonParser parser = new JsonParser(); JsonObject jsonObject = (JsonObject)parser.parse("{\"authenticated\":true,\"edOrg\":null,\"edOrgId\":null,\"email\":\"[email protected]\",\"external_id\":\"cgray\",\"full_name\":\"Mr Charles Gray\",\"granted_authorities\":[\"Destroyme\"],\"isAdminUser\":false,\"realm\":\"2013uz-d5ae70c9-55ef-11e2-b6be-68a86d3c2fde\",\"rights\":[\"READ_PUBLIC\",\"READ_GENERAL\",\"AGGREGATE_READ\"],\"sliRoles\":[\"Destroyme\"],\"tenantId\":\"[email protected]\",\"userType\":\"teacher\",\"user_id\":\"[email protected]@gmail.com\"}"); when(request.getSession()).thenReturn(mockSession); when(request.getRemoteAddr()).thenReturn("http: when(request.getServerName()).thenReturn("mock.slidev.org"); when(request.isSecure()).thenReturn(true); when(mockPropertiesDecryptor.getDecryptedClientId()).thenReturn("mock-client-id"); when(mockPropertiesDecryptor.getDecryptedClientSecret()).thenReturn("mock-client-secret"); when(mockPropertiesDecryptor.encrypt(anyString())).thenReturn("MOCK-ENCRYPTED-TOKEN"); when(mockSession.getAttribute(anyString())).thenReturn("Mock-OAUTH-TOKEN"); when(mockRESTClient.sessionCheck(anyString())).thenReturn(jsonObject); SLIAuthenticationEntryPoint sliAuthenticationEntryPoint = new SLIAuthenticationEntryPoint(); sliAuthenticationEntryPoint.setPropDecryptor(mockPropertiesDecryptor); sliAuthenticationEntryPoint.setApiClient(mockAPIClient); sliAuthenticationEntryPoint.setRestClient(mockRESTClient); sliAuthenticationEntryPoint.setApiUrl("/api/mock/uri"); sliAuthenticationEntryPoint.setCallbackUrl("http: sliAuthenticationEntryPoint.commence(request,response,mockAuthenticationException); } |
### Question:
Response extends WadlElement { public List<String> getStatusCodes() { return statusCodes; } Response(final List<String> statusCodes, final List<Documentation> doc, final List<Param> params,
final List<Representation> representations); List<String> getStatusCodes(); List<Param> getParams(); List<Representation> getRepresentations(); @Override String toString(); }### Answer:
@Test public void testGetStatusCodes() { assertEquals(STATUS_CODES, response.getStatusCodes()); } |
### Question:
TenantMongoDA implements TenantDA { @Override public void insertTenant(TenantRecord tenant) { if (entityRepository.findOne(TENANT_COLLECTION, new NeutralQuery(new NeutralCriteria(TENANT_ID, "=", tenant.getTenantId()))) == null) { entityRepository.create(TENANT_COLLECTION, getTenantBody(tenant)); } } @Override List<String> getLzPaths(); @Override String getTenantId(String lzPath); @Override void insertTenant(TenantRecord tenant); @Override @SuppressWarnings("unchecked") String getTenantEdOrg(String lzPath); Repository<Entity> getEntityRepository(); void setEntityRepository(Repository<Entity> entityRepository); @SuppressWarnings("unchecked") @Override Map<String, List<String>> getPreloadFiles(String ingestionServer); @Override boolean tenantDbIsReady(String tenantId); @Override void setTenantReadyFlag(String tenantId); @Override void unsetTenantReadyFlag(String tenantId); @Override boolean updateAndAquireOnboardingLock(String tenantId); @Override void removeInvalidTenant(String lzPath); @Override Map<String, List<String>> getPreloadFiles(); @Override List<String> getAllTenantDbs(); static final String TENANT_ID; static final String DB_NAME; static final String INGESTION_SERVER; static final String PATH; static final String LANDING_ZONE; static final String PRELOAD_DATA; static final String PRELOAD_STATUS; static final String PRELOAD_FILES; static final String TENANT_COLLECTION; static final String TENANT_TYPE; static final String EDUCATION_ORGANIZATION; static final String DESC; static final String ALL_STATUS_FIELDS; static final String STATUS_FIELD; }### Answer:
@Test public void shouldInsertTenant() { TenantRecord tenantRecord = createTestTenantRecord(); tenantDA.insertTenant(tenantRecord); Mockito.verify(mockRepository).create(Mockito.eq("tenant"), Mockito.argThat(new IsCorrectBody(tenantRecord))); } |
### Question:
Response extends WadlElement { public List<Param> getParams() { return params; } Response(final List<String> statusCodes, final List<Documentation> doc, final List<Param> params,
final List<Representation> representations); List<String> getStatusCodes(); List<Param> getParams(); List<Representation> getRepresentations(); @Override String toString(); }### Answer:
@Test public void testGetParams() { assertEquals(PARAMS, response.getParams()); } |
### Question:
Response extends WadlElement { public List<Representation> getRepresentations() { return representations; } Response(final List<String> statusCodes, final List<Documentation> doc, final List<Param> params,
final List<Representation> representations); List<String> getStatusCodes(); List<Param> getParams(); List<Representation> getRepresentations(); @Override String toString(); }### Answer:
@Test public void testGetRepresentations() { assertEquals(REPRESENTATIONS, response.getRepresentations()); } |
### Question:
Response extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("statusCodes").append(" : ").append(statusCodes); sb.append(", "); sb.append("params").append(" : ").append(params); sb.append(", "); sb.append("representations").append(" : ").append(representations); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Response(final List<String> statusCodes, final List<Documentation> doc, final List<Param> params,
final List<Representation> representations); List<String> getStatusCodes(); List<Param> getParams(); List<Representation> getRepresentations(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(response.toString())); } |
### Question:
Request extends WadlElement { public List<Param> getParams() { return params; } Request(final List<Documentation> doc, final List<Param> params, final List<Representation> representations); List<Param> getParams(); List<Representation> getRepresentations(); @Override String toString(); }### Answer:
@Test public void testGetParams() { assertEquals(PARAMS, request.getParams()); } |
### Question:
Request extends WadlElement { public List<Representation> getRepresentations() { return representations; } Request(final List<Documentation> doc, final List<Param> params, final List<Representation> representations); List<Param> getParams(); List<Representation> getRepresentations(); @Override String toString(); }### Answer:
@Test public void testGetRepresentations() { assertEquals(REPRESENTATIONS, request.getRepresentations()); } |
### Question:
Request extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("params").append(" : ").append(params); sb.append(", "); sb.append("representations").append(" : ").append(representations); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Request(final List<Documentation> doc, final List<Param> params, final List<Representation> representations); List<Param> getParams(); List<Representation> getRepresentations(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(request.toString())); } |
### Question:
Representation extends WadlElement { public String getId() { return id; } Representation(final String id, final QName elementName, final String mediaType,
final List<String> profiles, final List<Documentation> doc, final List<Param> params); String getId(); QName getElementName(); String getMediaType(); List<String> getProfiles(); List<Param> getParams(); @Override String toString(); }### Answer:
@Test public void testGetId() { assertEquals(ID, representation.getId()); } |
### Question:
Representation extends WadlElement { public String getMediaType() { return mediaType; } Representation(final String id, final QName elementName, final String mediaType,
final List<String> profiles, final List<Documentation> doc, final List<Param> params); String getId(); QName getElementName(); String getMediaType(); List<String> getProfiles(); List<Param> getParams(); @Override String toString(); }### Answer:
@Test public void testGetMediaType() { assertEquals(MEDIA_TYPE, representation.getMediaType()); } |
### Question:
Representation extends WadlElement { public List<Param> getParams() { return params; } Representation(final String id, final QName elementName, final String mediaType,
final List<String> profiles, final List<Documentation> doc, final List<Param> params); String getId(); QName getElementName(); String getMediaType(); List<String> getProfiles(); List<Param> getParams(); @Override String toString(); }### Answer:
@Test public void testGetParams() { assertEquals(PARAMS, representation.getParams()); } |
### Question:
Representation extends WadlElement { public List<String> getProfiles() { return profiles; } Representation(final String id, final QName elementName, final String mediaType,
final List<String> profiles, final List<Documentation> doc, final List<Param> params); String getId(); QName getElementName(); String getMediaType(); List<String> getProfiles(); List<Param> getParams(); @Override String toString(); }### Answer:
@Test public void testGetProfiles() { assertEquals(PROFILES, representation.getProfiles()); } |
### Question:
Representation extends WadlElement { public QName getElementName() { return elementName; } Representation(final String id, final QName elementName, final String mediaType,
final List<String> profiles, final List<Documentation> doc, final List<Param> params); String getId(); QName getElementName(); String getMediaType(); List<String> getProfiles(); List<Param> getParams(); @Override String toString(); }### Answer:
@Test public void testGetElementName() { assertEquals(ELEMENT_NAME, representation.getElementName()); } |
### Question:
Representation extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("id").append(" : ").append(id); sb.append(", "); sb.append("elementName").append(" : ").append(elementName); sb.append(", "); sb.append("mediaType").append(" : ").append(mediaType); sb.append(", "); sb.append("profiles").append(" : ").append(profiles); sb.append(", "); sb.append("params").append(" : ").append(params); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Representation(final String id, final QName elementName, final String mediaType,
final List<String> profiles, final List<Documentation> doc, final List<Param> params); String getId(); QName getElementName(); String getMediaType(); List<String> getProfiles(); List<Param> getParams(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(representation.toString())); } |
### Question:
Grammars extends WadlElement { public List<Include> getIncludes() { return includes; } Grammars(final List<Documentation> doc, final List<Include> includes); List<Include> getIncludes(); @Override String toString(); }### Answer:
@Test public void testGetIncludes() { assertEquals(INCLUDES, grammars.getIncludes()); } |
### Question:
Grammars extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("includes").append(" : ").append(includes); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Grammars(final List<Documentation> doc, final List<Include> includes); List<Include> getIncludes(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(grammars.toString())); } |
### Question:
Documentation { public String getTitle() { return title; } Documentation(final String title, final String language, final List<DmNode> contents); String getTitle(); String getLanguage(); List<DmNode> getContents(); @Override String toString(); }### Answer:
@Test public void testGetTitle() { assertEquals(TITLE, documentation.getTitle()); } |
### Question:
Documentation { public String getLanguage() { return language; } Documentation(final String title, final String language, final List<DmNode> contents); String getTitle(); String getLanguage(); List<DmNode> getContents(); @Override String toString(); }### Answer:
@Test public void testGetLanguage() { assertEquals(LANGUAGE, documentation.getLanguage()); } |
### Question:
Documentation { public List<DmNode> getContents() { return contents; } Documentation(final String title, final String language, final List<DmNode> contents); String getTitle(); String getLanguage(); List<DmNode> getContents(); @Override String toString(); }### Answer:
@Test public void testGetContents() { assertEquals(CONTENTS, documentation.getContents()); } |
### Question:
Documentation { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("language").append(" : ").append(language); sb.append(", "); sb.append("title").append(" : ").append(title); sb.append(", "); sb.append("contents").append(" : ").append(contents); sb.append("}"); return sb.toString(); } Documentation(final String title, final String language, final List<DmNode> contents); String getTitle(); String getLanguage(); List<DmNode> getContents(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(documentation.toString())); } |
### Question:
Option extends WadlElement { public String getValue() { return value; } Option(final String value, final List<Documentation> doc); String getValue(); }### Answer:
@Test public void testGetValue() { assertEquals(VALUE, option.getValue()); } |
### Question:
ResourceType extends WadlElement { public String getId() { return id; } ResourceType(final String id, final List<Documentation> doc, final List<Param> params,
final Method method, final Resource resource); String getId(); List<Param> getParams(); Method getMethod(); Resource getResource(); }### Answer:
@Test public void testGetId() { assertEquals(ID, resourceType.getId()); } |
### Question:
FileEntryLatch { @Handler public boolean lastFileProcessed(Exchange exchange) throws Exception { FileEntryWorkNote workNote = exchange.getIn().getBody(FileEntryWorkNote.class); String batchJobId = workNote.getBatchJobId(); TenantContext.setJobId(batchJobId); if (batchJobDAO.updateFileEntryLatch(workNote.getBatchJobId(), workNote.getFileEntry().getFileName())) { RangedWorkNote wn = RangedWorkNote.createSimpleWorkNote(batchJobId); exchange.getIn().setBody(wn, RangedWorkNote.class); return true; } return false; } @Handler boolean lastFileProcessed(Exchange exchange); BatchJobDAO getBatchJobDAO(); void setBatchJobDAO(BatchJobDAO batchJobDAO); }### Answer:
@Test public void testReceive() throws Exception { Exchange exchange = new DefaultExchange(new DefaultCamelContext()); IngestionFileEntry entry = new IngestionFileEntry("/", FileFormat.EDFI_XML, FileType.XML_STUDENT_PROGRAM, "fileName", "111"); FileEntryWorkNote workNote = new FileEntryWorkNote("batchJobId", entry, false); boolean fileEntryLatchOpened; exchange.getIn().setBody(workNote, FileEntryWorkNote.class); fileEntryLatchOpened = fileEntryLatch.lastFileProcessed(exchange); Assert.assertFalse(fileEntryLatchOpened); fileEntryLatchOpened = fileEntryLatch.lastFileProcessed(exchange); Assert.assertTrue(fileEntryLatchOpened); } |
### Question:
ResourceType extends WadlElement { public Method getMethod() { return method; } ResourceType(final String id, final List<Documentation> doc, final List<Param> params,
final Method method, final Resource resource); String getId(); List<Param> getParams(); Method getMethod(); Resource getResource(); }### Answer:
@Test public void testGetMethod() { assertEquals(METHOD, resourceType.getMethod()); } |
### Question:
ResourceType extends WadlElement { public List<Param> getParams() { return params; } ResourceType(final String id, final List<Documentation> doc, final List<Param> params,
final Method method, final Resource resource); String getId(); List<Param> getParams(); Method getMethod(); Resource getResource(); }### Answer:
@Test public void testGetParams() { assertEquals(PARAMS, resourceType.getParams()); } |
### Question:
ResourceType extends WadlElement { public Resource getResource() { return resource; } ResourceType(final String id, final List<Documentation> doc, final List<Param> params,
final Method method, final Resource resource); String getId(); List<Param> getParams(); Method getMethod(); Resource getResource(); }### Answer:
@Test public void testGetResource() { assertEquals(RESOURCE, resourceType.getResource()); } |
### Question:
RestHelper { public static final List<Param> computeRequestTemplateParams(final Resource resource, final Stack<Resource> ancestors) { final List<Param> params = new LinkedList<Param>(); final List<Resource> rightToLeftResources = new LinkedList<Resource>(); rightToLeftResources.addAll(reverse(ancestors)); rightToLeftResources.add(resource); for (final Resource rightToLeftResource : rightToLeftResources) { for (final Param param : rightToLeftResource.getParams()) { if (param.getStyle() == ParamStyle.TEMPLATE) { params.add(param); } } } return Collections.unmodifiableList(params); } static final List<Param> computeRequestTemplateParams(final Resource resource,
final Stack<Resource> ancestors); static final List<T> reverse(final List<T> strings); }### Answer:
@Test public void testComputeRequestTemplateParamsEmptyAncestors() { Stack<Resource> resources = new Stack<Resource>(); Param r1p1 = mock(Param.class); when(r1p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r1p1.getId()).thenReturn(R1P1_ID); List<Param> r1Params = new ArrayList<Param>(1); r1Params.add(r1p1); Resource r1 = mock(Resource.class); when(r1.getParams()).thenReturn(r1Params); List<Param> templateParams = RestHelper.computeRequestTemplateParams(r1, resources); assertEquals(1, templateParams.size()); assertEquals(R1P1_ID, templateParams.get(0).getId()); }
@Test public void testComputeRequestTemplateParams() { Stack<Resource> resources = new Stack<Resource>(); Param r1p1 = mock(Param.class); when(r1p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r1p1.getId()).thenReturn(R1P1_ID); List<Param> r1Params = new ArrayList<Param>(1); r1Params.add(r1p1); Resource r1 = mock(Resource.class); when(r1.getParams()).thenReturn(r1Params); Param r2p1 = mock(Param.class); when(r2p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r2p1.getId()).thenReturn(R2P1_ID); Param r2p2 = mock(Param.class); when(r2p2.getStyle()).thenReturn(ParamStyle.QUERY); when(r2p2.getId()).thenReturn(R2P2_ID); List<Param> r2Params = new ArrayList<Param>(2); r2Params.add(r2p1); r2Params.add(r2p2); Resource r2 = mock(Resource.class); when(r2.getParams()).thenReturn(r2Params); Param r3p1 = mock(Param.class); when(r3p1.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r3p1.getId()).thenReturn(R3P1_ID); Param r3p2 = mock(Param.class); when(r3p2.getStyle()).thenReturn(ParamStyle.TEMPLATE); when(r3p2.getId()).thenReturn(R3P2_ID); List<Param> r3Params = new ArrayList<Param>(2); r3Params.add(r3p1); r3Params.add(r3p2); Resource r3 = mock(Resource.class); when(r3.getParams()).thenReturn(r3Params); resources.push(r2); resources.push(r3); List<Param> templateParams = RestHelper.computeRequestTemplateParams(r1, resources); assertEquals(4, templateParams.size()); assertEquals(R3P1_ID, templateParams.get(0).getId()); assertEquals(R3P2_ID, templateParams.get(1).getId()); assertEquals(R2P1_ID, templateParams.get(2).getId()); assertEquals(R1P1_ID, templateParams.get(3).getId()); } |
### Question:
RestHelper { public static final <T> List<T> reverse(final List<T> strings) { final LinkedList<T> result = new LinkedList<T>(); for (final T s : strings) { result.addFirst(s); } return Collections.unmodifiableList(result); } static final List<Param> computeRequestTemplateParams(final Resource resource,
final Stack<Resource> ancestors); static final List<T> reverse(final List<T> strings); }### Answer:
@Test public void testReverse() { List<Integer> numbers = new ArrayList<Integer>(3); numbers.add(1); numbers.add(2); numbers.add(3); List<Integer> reversedNumbers = RestHelper.reverse(numbers); Integer crntNumber = 3; assertEquals(3, reversedNumbers.size()); for (Integer i : reversedNumbers) { assertEquals(crntNumber--, i); } }
@Test public void testReverseEmpty() { List<Integer> numbers = new ArrayList<Integer>(0); List<Integer> reversedNumbers = RestHelper.reverse(numbers); assertEquals(0, reversedNumbers.size()); }
@Test public void testReverseOne() { List<Integer> numbers = new ArrayList<Integer>(1); numbers.add(9); List<Integer> reversedNumbers = RestHelper.reverse(numbers); assertEquals(1, reversedNumbers.size()); assertEquals((Integer) 9, (Integer) reversedNumbers.get(0)); } |
### Question:
Link extends WadlElement { public String getResourceType() { return resourceType; } Link(final String resourceType, final String rel, final String rev, final List<Documentation> doc); String getResourceType(); String getRel(); String getRev(); }### Answer:
@Test public void testGetResourceType() { assertEquals(RESOURCE_TYPE, link.getResourceType()); } |
### Question:
Link extends WadlElement { public String getRel() { return rel; } Link(final String resourceType, final String rel, final String rev, final List<Documentation> doc); String getResourceType(); String getRel(); String getRev(); }### Answer:
@Test public void testGetRelType() { assertEquals(REL, link.getRel()); } |
### Question:
BatchJobManager { public boolean isEligibleForDeltaPurge(Exchange exchange) { WorkNote workNote = exchange.getIn().getBody(WorkNote.class); String jobId = workNote.getBatchJobId(); String deltaMode = batchJobDAO.getDuplicateDetectionMode(jobId); if(deltaMode != null && isDeltaPurgeMode(deltaMode)) { return true; } return false; } void prepareTenantContext(Exchange exchange); boolean isDryRun(Exchange exchange); boolean hasErrors(Exchange exchange); boolean isEligibleForDeltaPurge(Exchange exchange); }### Answer:
@Test public void testPurgeDisableDeltas() throws Exception { Mockito.when(batchJobDAO.getDuplicateDetectionMode(jobId)).thenReturn(RecordHash.RECORD_HASH_MODE_DISABLE); Exchange exchange = new DefaultExchange(new DefaultCamelContext()); WorkNote workNote = new WorkNote(jobId, false); exchange.getIn().setBody(workNote); boolean isEligible = batchJobManager.isEligibleForDeltaPurge(exchange); Assert.assertTrue(isEligible); }
@Test public void testPurgeResetDeltas() throws Exception { Mockito.when(batchJobDAO.getDuplicateDetectionMode(jobId)).thenReturn(RecordHash.RECORD_HASH_MODE_RESET); Exchange exchange = new DefaultExchange(new DefaultCamelContext()); WorkNote workNote = new WorkNote(jobId, false); exchange.getIn().setBody(workNote); boolean isEligible = batchJobManager.isEligibleForDeltaPurge(exchange); Assert.assertTrue(isEligible); }
@Test public void testNoPurgeDeltas() throws Exception { Mockito.when(batchJobDAO.getDuplicateDetectionMode(jobId)).thenReturn(null); Exchange exchange = new DefaultExchange(new DefaultCamelContext()); WorkNote workNote = new WorkNote(jobId, false); exchange.getIn().setBody(workNote); boolean isEligible = batchJobManager.isEligibleForDeltaPurge(exchange); Assert.assertFalse(isEligible); } |
### Question:
Link extends WadlElement { public String getRev() { return rev; } Link(final String resourceType, final String rel, final String rev, final List<Documentation> doc); String getResourceType(); String getRel(); String getRev(); }### Answer:
@Test public void testGetRev() { assertEquals(REV, link.getRev()); } |
### Question:
Resource extends WadlElement { public String getId() { return id; } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testGetId() { assertEquals(ID, resource.getId()); } |
### Question:
Resource extends WadlElement { public List<Method> getMethods() { return methods; } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testGetMethods() { assertEquals(METHODS, resource.getMethods()); } |
### Question:
Resource extends WadlElement { public List<Param> getParams() { return params; } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testGetParams() { assertEquals(PARAMS, resource.getParams()); } |
### Question:
Resource extends WadlElement { public String getPath() { return path; } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testGetPath() { assertEquals(PATH, resource.getPath()); } |
### Question:
Resource extends WadlElement { public String getQueryType() { return queryType; } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testGetQueryType() { assertEquals(QUERY_TYPE, resource.getQueryType()); } |
### Question:
Resource extends WadlElement { public List<Resource> getResources() { return resources; } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testGetResources() { assertEquals(RESOURCES, resource.getResources()); } |
### Question:
Resource extends WadlElement { public List<String> getType() { return type; } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testGetType() { assertEquals(TYPE, resource.getType()); } |
### Question:
Resource extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("id").append(" : ").append(id); sb.append(", "); sb.append("type").append(" : ").append(type); sb.append(", "); sb.append("queryType").append(" : ").append(queryType); sb.append(", "); sb.append("path").append(" : ").append(path); sb.append(", "); sb.append("params").append(" : ").append(params); sb.append(", "); sb.append("methods").append(" : ").append(methods); sb.append(", "); sb.append("resources").append(" : ").append(resources); sb.append("}"); return sb.toString(); } Resource(final String id, final List<String> type, final String queryType, final String path,
final List<Documentation> doc, final List<Param> params, final List<Method> methods,
final List<Resource> resources, final String resourceClass); String getId(); List<String> getType(); String getQueryType(); String getPath(); List<Param> getParams(); List<Method> getMethods(); List<Resource> getResources(); @Override String toString(); String getResourceClass(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(resource.toString())); } |
### Question:
Param extends WadlElement { public String getName() { return name; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetName() { assertEquals(NAME, param.getName()); } |
### Question:
Param extends WadlElement { public ParamStyle getStyle() { return style; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetStyle() { assertEquals(STYLE, param.getStyle()); } |
### Question:
Param extends WadlElement { public String getId() { return id; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetId() { assertEquals(ID, param.getId()); } |
### Question:
Param extends WadlElement { public QName getType() { return type; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetType() { assertEquals(TYPE, param.getType()); } |
### Question:
Param extends WadlElement { public String getDefault() { return defaultValue; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetDefault() { assertEquals(DEFAULT_VALUE, param.getDefault()); } |
### Question:
Param extends WadlElement { public boolean getRequired() { return required; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetRequired() { assertEquals(REQUIRED, param.getRequired()); } |
### Question:
Param extends WadlElement { public boolean getRepeating() { return repeating; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetRepeating() { assertEquals(REPEATING, param.getRepeating()); } |
### Question:
Param extends WadlElement { public String getFixed() { return fixed; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetFixed() { assertEquals(FIXED, param.getFixed()); } |
### Question:
Param extends WadlElement { public String getPath() { return path; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetPath() { assertEquals(PATH, param.getPath()); } |
### Question:
Param extends WadlElement { public List<Option> getOptions() { return options; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetOptions() { assertEquals(OPTIONS, param.getOptions()); } |
### Question:
Param extends WadlElement { public Link getLink() { return link; } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testGetLink() { assertEquals(LINK, param.getLink()); } |
### Question:
Param extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("name").append(" : ").append(name); sb.append(", "); sb.append("style").append(" : ").append(style); sb.append(", "); sb.append("id").append(" : ").append(id); sb.append(", "); sb.append("type").append(" : ").append(type); sb.append(", "); sb.append("default").append(" : ").append(defaultValue); sb.append(", "); sb.append("required").append(" : ").append(required); sb.append(", "); sb.append("repeating").append(" : ").append(repeating); sb.append(", "); sb.append("fixed").append(" : ").append(fixed); sb.append(", "); sb.append("path").append(" : ").append(path); sb.append(", "); sb.append("options").append(" : ").append(options); sb.append(", "); sb.append("link").append(" : ").append(link); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Param(final String name, final ParamStyle style, final String id, final QName type,
final String defaultValue, final boolean required, final boolean repeating, final String fixed,
final String path, final List<Documentation> doc, final List<Option> options, final Link link); String getName(); ParamStyle getStyle(); String getId(); QName getType(); String getDefault(); boolean getRequired(); boolean getRepeating(); String getFixed(); String getPath(); List<Option> getOptions(); Link getLink(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(param.toString())); } |
### Question:
Method extends WadlElement { public String getId() { return id; } Method(final String id, final String verb, final List<Documentation> doc, final Request request,
final List<Response> responses); String getId(); String getVerb(); Request getRequest(); List<Response> getResponses(); @Override String toString(); static final String NAME_HTTP_GET; static final String NAME_HTTP_POST; static final String NAME_HTTP_PUT; static final String NAME_HTTP_DELETE; static final String NAME_HTTP_PATCH; }### Answer:
@Test public void testGetId() { assertEquals(ID, method.getId()); } |
### Question:
Method extends WadlElement { public Request getRequest() { return request; } Method(final String id, final String verb, final List<Documentation> doc, final Request request,
final List<Response> responses); String getId(); String getVerb(); Request getRequest(); List<Response> getResponses(); @Override String toString(); static final String NAME_HTTP_GET; static final String NAME_HTTP_POST; static final String NAME_HTTP_PUT; static final String NAME_HTTP_DELETE; static final String NAME_HTTP_PATCH; }### Answer:
@Test public void testGetRequest() { assertEquals(REQUEST, method.getRequest()); } |
### Question:
Method extends WadlElement { public List<Response> getResponses() { return responses; } Method(final String id, final String verb, final List<Documentation> doc, final Request request,
final List<Response> responses); String getId(); String getVerb(); Request getRequest(); List<Response> getResponses(); @Override String toString(); static final String NAME_HTTP_GET; static final String NAME_HTTP_POST; static final String NAME_HTTP_PUT; static final String NAME_HTTP_DELETE; static final String NAME_HTTP_PATCH; }### Answer:
@Test public void testGetResponses() { assertEquals(RESPONSES, method.getResponses()); } |
### Question:
Method extends WadlElement { public String getVerb() { return verb; } Method(final String id, final String verb, final List<Documentation> doc, final Request request,
final List<Response> responses); String getId(); String getVerb(); Request getRequest(); List<Response> getResponses(); @Override String toString(); static final String NAME_HTTP_GET; static final String NAME_HTTP_POST; static final String NAME_HTTP_PUT; static final String NAME_HTTP_DELETE; static final String NAME_HTTP_PATCH; }### Answer:
@Test public void testGetVerb() { assertEquals(VERB, method.getVerb()); } |
### Question:
Method extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("id").append(" : ").append(id); sb.append(", "); sb.append("name").append(" : ").append(verb); sb.append(", "); sb.append("request").append(" : ").append(request); sb.append(", "); sb.append("responses").append(" : ").append(responses); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Method(final String id, final String verb, final List<Documentation> doc, final Request request,
final List<Response> responses); String getId(); String getVerb(); Request getRequest(); List<Response> getResponses(); @Override String toString(); static final String NAME_HTTP_GET; static final String NAME_HTTP_POST; static final String NAME_HTTP_PUT; static final String NAME_HTTP_DELETE; static final String NAME_HTTP_PATCH; }### Answer:
@Test public void testToString() { assertTrue(!"".equals(method.toString())); } |
### Question:
Resources extends WadlElement { public String getBase() { return base; } Resources(final String base, final List<Documentation> doc, final List<Resource> resources); String getBase(); List<Resource> getResources(); @Override String toString(); }### Answer:
@Test public void testGetBase() { assertEquals(BASE, resources.getBase()); } |
### Question:
Resources extends WadlElement { public List<Resource> getResources() { return resources; } Resources(final String base, final List<Documentation> doc, final List<Resource> resources); String getBase(); List<Resource> getResources(); @Override String toString(); }### Answer:
@Test public void testGetResources() { assertEquals(RESOURCE_LIST, resources.getResources()); } |
### Question:
Resources extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("base").append(" : ").append(base); sb.append(", "); sb.append("resources").append(" : ").append(resources); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Resources(final String base, final List<Documentation> doc, final List<Resource> resources); String getBase(); List<Resource> getResources(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(resources.toString())); } |
### Question:
Include extends WadlElement { public String getHref() { return href; } Include(final String href, final List<Documentation> doc); String getHref(); }### Answer:
@Test public void testGetHref() { assertEquals(HREF, include.getHref()); } |
### Question:
ValidationController { public void doValidation(File path) { ReportStats reportStats = new SimpleReportStats(); if (path.isFile()) { if (path.getName().endsWith(".ctl")) { processControlFile(path.getParentFile().getAbsoluteFile(), path.getName(), reportStats); } else if (path.getName().endsWith(".zip")) { processZip(path, reportStats); } else { messageReport.error(reportStats, new FileSource(path.getName()), ValidationMessageCode.VALIDATION_0001); } } else { messageReport.error(reportStats, new DirectorySource(path.getPath(), path.getName()), ValidationMessageCode.VALIDATION_0015); } } void doValidation(File path); void processValidators(ControlFile cfile, ReportStats reportStats); void processZip(File zipFile, ReportStats reportStats); void processControlFile(File parentDirectoryOrZipFile, String ctlFile, ReportStats reportStats); Handler<Resource, String> getZipFileHandler(); void setZipFileHandler(Handler<Resource, String> zipFileHandler); ComplexValidator<IngestionFileEntry> getComplexValidator(); void setComplexValidator(ComplexValidator<IngestionFileEntry> complexValidator); Validator<ControlFile> getControlFilevalidator(); void setControlFilevalidator(Validator<ControlFile> controlFilevalidator); AbstractMessageReport getMessageReport(); void setMessageReport(AbstractMessageReport messageReport); }### Answer:
@Test public void testDirectory() throws NoSuchFieldException, IllegalAccessException, IOException { File ctlFile = Mockito.mock(File.class); Mockito.when(ctlFile.getName()).thenReturn("Test"); Mockito.when(ctlFile.isFile()).thenReturn(false); AbstractMessageReport messageReport = Mockito.mock(AbstractMessageReport.class); PrivateAccessor.setField(validationController, "messageReport", messageReport); validationController.doValidation(ctlFile); Mockito.verify(messageReport, Mockito.atLeastOnce()).error(Matchers.any(ReportStats.class), Matchers.any(Source.class), Matchers.eq(ValidationMessageCode.VALIDATION_0015)); }
@Test public void testDoValidationInvalidFile() throws NoSuchFieldException, IllegalAccessException, IOException { AbstractMessageReport messageReport = Mockito.mock(AbstractMessageReport.class); PrivateAccessor.setField(validationController, "messageReport", messageReport); File invalidFile = Mockito.mock(File.class); Mockito.when(invalidFile.getName()).thenReturn("Test.txt"); Mockito.when(invalidFile.isFile()).thenReturn(true); validationController.doValidation(invalidFile); Mockito.verify(messageReport, Mockito.atLeastOnce()).error(Matchers.any(ReportStats.class), Matchers.any(Source.class), Matchers.eq(ValidationMessageCode.VALIDATION_0001)); } |
### Question:
Application extends WadlElement { public Grammars getGrammars() { return grammars; } Application(final List<Documentation> doc, final Grammars grammars, final Resources resources,
final List<ResourceType> resourceTypes, final List<Method> methods,
final List<Representation> representations, final List<Representation> faults); Grammars getGrammars(); Resources getResources(); List<ResourceType> getResourceTypes(); List<Method> getMethods(); List<Representation> getRepresentations(); List<Representation> getFaults(); @Override String toString(); }### Answer:
@Test public void testGetGrammars() { assertEquals(GRAMMARS, application.getGrammars()); } |
### Question:
Application extends WadlElement { public Resources getResources() { return resources; } Application(final List<Documentation> doc, final Grammars grammars, final Resources resources,
final List<ResourceType> resourceTypes, final List<Method> methods,
final List<Representation> representations, final List<Representation> faults); Grammars getGrammars(); Resources getResources(); List<ResourceType> getResourceTypes(); List<Method> getMethods(); List<Representation> getRepresentations(); List<Representation> getFaults(); @Override String toString(); }### Answer:
@Test public void testGetResources() { assertEquals(RESOURCES, application.getResources()); } |
### Question:
Application extends WadlElement { public List<ResourceType> getResourceTypes() { return resourceTypes; } Application(final List<Documentation> doc, final Grammars grammars, final Resources resources,
final List<ResourceType> resourceTypes, final List<Method> methods,
final List<Representation> representations, final List<Representation> faults); Grammars getGrammars(); Resources getResources(); List<ResourceType> getResourceTypes(); List<Method> getMethods(); List<Representation> getRepresentations(); List<Representation> getFaults(); @Override String toString(); }### Answer:
@Test public void testGetResourceTypes() { assertEquals(RESOURCE_TYPES, application.getResourceTypes()); } |
### Question:
Application extends WadlElement { public List<Method> getMethods() { return methods; } Application(final List<Documentation> doc, final Grammars grammars, final Resources resources,
final List<ResourceType> resourceTypes, final List<Method> methods,
final List<Representation> representations, final List<Representation> faults); Grammars getGrammars(); Resources getResources(); List<ResourceType> getResourceTypes(); List<Method> getMethods(); List<Representation> getRepresentations(); List<Representation> getFaults(); @Override String toString(); }### Answer:
@Test public void testGetMethods() { assertEquals(METHODS, application.getMethods()); } |
### Question:
Application extends WadlElement { public List<Representation> getRepresentations() { return representations; } Application(final List<Documentation> doc, final Grammars grammars, final Resources resources,
final List<ResourceType> resourceTypes, final List<Method> methods,
final List<Representation> representations, final List<Representation> faults); Grammars getGrammars(); Resources getResources(); List<ResourceType> getResourceTypes(); List<Method> getMethods(); List<Representation> getRepresentations(); List<Representation> getFaults(); @Override String toString(); }### Answer:
@Test public void testGetRepresentations() { assertEquals(REPRESENTATIONS, application.getRepresentations()); } |
### Question:
Application extends WadlElement { public List<Representation> getFaults() { return faults; } Application(final List<Documentation> doc, final Grammars grammars, final Resources resources,
final List<ResourceType> resourceTypes, final List<Method> methods,
final List<Representation> representations, final List<Representation> faults); Grammars getGrammars(); Resources getResources(); List<ResourceType> getResourceTypes(); List<Method> getMethods(); List<Representation> getRepresentations(); List<Representation> getFaults(); @Override String toString(); }### Answer:
@Test public void testGetFaults() { assertEquals(REPRESENTATIONS, application.getFaults()); } |
### Question:
Application extends WadlElement { @Override public String toString() { final StringBuilder sb = new StringBuilder(); sb.append("{"); sb.append("grammars").append(" : ").append(grammars); sb.append(", "); sb.append("resources").append(" : ").append(resources); sb.append(", "); sb.append("resourceTypes").append(" : ").append(resourceTypes); sb.append(", "); sb.append("methods").append(" : ").append(methods); sb.append(", "); sb.append("representations").append(" : ").append(representations); sb.append(", "); sb.append("faults").append(" : ").append(faults); sb.append(", "); sb.append("doc").append(" : ").append(getDocumentation()); sb.append("}"); return sb.toString(); } Application(final List<Documentation> doc, final Grammars grammars, final Resources resources,
final List<ResourceType> resourceTypes, final List<Method> methods,
final List<Representation> representations, final List<Representation> faults); Grammars getGrammars(); Resources getResources(); List<ResourceType> getResourceTypes(); List<Method> getMethods(); List<Representation> getRepresentations(); List<Representation> getFaults(); @Override String toString(); }### Answer:
@Test public void testToString() { assertTrue(!"".equals(application.toString())); } |
### Question:
SelectorDoc { public static void main(String[] args) { try { new SelectorDoc(args[0], args[1]).generateSelectorDocumentation(); } catch (IOException e) { LOG.warn(e.getMessage()); } } SelectorDoc(String inputXmiFilename, String outputXmlFilename); static void main(String[] args); static final String ATTRIBUTE; static final String ASSOCIATION; }### Answer:
@Test public void testMain() throws IOException { SelectorDoc.main(ARGS); File file = new File(OUTPUT_FILENAME); assertTrue(file.exists()); file.delete(); } |
### Question:
SelectorDoc { protected boolean writeSelectorDocumentationToFile(String documentationString, Writer output) { if (documentationString == null) { return false; } try { output.write(documentationString); output.flush(); output.close(); } catch (IOException e) { LOG.warn(e.getMessage()); return false; } return true; } SelectorDoc(String inputXmiFilename, String outputXmlFilename); static void main(String[] args); static final String ATTRIBUTE; static final String ASSOCIATION; }### Answer:
@Test public void testWriteBuffer() throws IOException { Writer writer = mock(Writer.class); assertTrue(this.selectorDoc.writeSelectorDocumentationToFile("foo", writer)); } |
### Question:
SelectorDoc { protected void appendClassTypeAttributes(StringBuffer stringBuffer, ClassType classType) { for (Attribute attribute : classType.getAttributes()) { stringBuffer.append(String.format(FEATURE, ATTRIBUTE, attribute.getName())); } } SelectorDoc(String inputXmiFilename, String outputXmlFilename); static void main(String[] args); static final String ATTRIBUTE; static final String ASSOCIATION; }### Answer:
@Test public void testAppendClassTypeAttributes() { this.selectorDoc.appendClassTypeAttributes(stringBuffer, CLASS_TYPE); String part1 = String.format(SelectorDoc.FEATURE, SelectorDoc.ATTRIBUTE, ATTRIBUTE1_NAME); String part2 = String.format(SelectorDoc.FEATURE, SelectorDoc.ATTRIBUTE, ATTRIBUTE2_NAME); String expectedToString = part1 + part2; assertEquals(expectedToString, stringBuffer.toString()); } |
### Question:
SelectorDoc { protected void appendClassTypeAssociations(StringBuffer stringBuffer, ClassType classType, ModelIndex modelIndex) { for (AssociationEnd associationEnd : modelIndex.getAssociationEnds(classType.getId())) { stringBuffer.append(String.format(FEATURE, ASSOCIATION, associationEnd.getName())); } } SelectorDoc(String inputXmiFilename, String outputXmlFilename); static void main(String[] args); static final String ATTRIBUTE; static final String ASSOCIATION; }### Answer:
@Test public void testAppendClassTypeAssociations() { this.selectorDoc.appendClassTypeAssociations(stringBuffer, CLASS_TYPE, MODEL_INDEX); String part1 = String.format(SelectorDoc.FEATURE, SelectorDoc.ASSOCIATION, ASSOCIATION_END1_NAME); String part2 = String.format(SelectorDoc.FEATURE, SelectorDoc.ASSOCIATION, ASSOCIATION_END2_NAME); String expectedToString = part1 + part2; assertEquals(expectedToString, stringBuffer.toString()); } |
### Question:
SelectorDoc { protected String getSelectorDocumentation(ModelIndex modelIndex) { StringBuffer stringBuffer = new StringBuffer(); Map<String, ClassType> classTypes = modelIndex.getClassTypes(); for (Entry<String, ClassType> classTypeEntry : classTypes.entrySet()) { ClassType classType = classTypeEntry.getValue(); stringBuffer.append(String.format(SIMPLE_SECT_START, classType.getName())); stringBuffer.append(FEATURES_START); this.appendClassTypeAttributes(stringBuffer, classType); this.appendClassTypeAssociations(stringBuffer, classType, modelIndex); stringBuffer.append(FEATURES_END); stringBuffer.append(SIMPLE_SECT_END); } return stringBuffer.toString(); } SelectorDoc(String inputXmiFilename, String outputXmlFilename); static void main(String[] args); static final String ATTRIBUTE; static final String ASSOCIATION; }### Answer:
@Test public void testGetSelectorDocumentation() { String receivedResult = this.selectorDoc.getSelectorDocumentation(MODEL_INDEX); String part1 = String.format(SelectorDoc.SIMPLE_SECT_START, CLASS_TYPE_NAME) + SelectorDoc.FEATURES_START; String part2 = String.format(SelectorDoc.FEATURE, SelectorDoc.ATTRIBUTE, ATTRIBUTE1_NAME); String part3 = String.format(SelectorDoc.FEATURE, SelectorDoc.ATTRIBUTE, ATTRIBUTE2_NAME); String part4 = String.format(SelectorDoc.FEATURE, SelectorDoc.ASSOCIATION, ASSOCIATION_END1_NAME); String part5 = String.format(SelectorDoc.FEATURE, SelectorDoc.ASSOCIATION, ASSOCIATION_END2_NAME); String part6 = SelectorDoc.FEATURES_END + SelectorDoc.SIMPLE_SECT_END; String expectedToString = part1 + part2 + part3 + part4 + part5 + part6; assertEquals(expectedToString, receivedResult); } |
### Question:
SelectorDoc { protected ModelIndex getModelIndex(Model model) { if (model != null) { return new DefaultModelIndex(model); } else { return null; } } SelectorDoc(String inputXmiFilename, String outputXmlFilename); static void main(String[] args); static final String ATTRIBUTE; static final String ASSOCIATION; }### Answer:
@Test public void testGetModelIndex() throws FileNotFoundException { Model model = this.selectorDoc.readModel(); ModelIndex modelIndex = this.selectorDoc.getModelIndex(model); assertNotNull("Expected non-null modelIndex", modelIndex); } |
### Question:
XsdGen { public static void main(final String[] args) { final OptionParser parser = new OptionParser(); final OptionSpec<?> helpSpec = parser.acceptsAll(ARGUMENT_HELP, "Show help"); final OptionSpec<File> documentFileSpec = optionSpec(parser, ARGUMENT_DOCUMENT_FILE, "Domain file", File.class); final OptionSpec<File> xmiFileSpec = optionSpec(parser, ARGUMENT_XMI, "XMI file", File.class); final OptionSpec<String> outFileSpec = optionSpec(parser, ARGUMENT_OUT_FILE, "Output file", String.class); final OptionSpec<File> outFolderSpec = optionSpec(parser, ARGUMENT_OUT_FOLDER, "Output folder", File.class); final OptionSpec<String> plugInNameSpec = optionSpec(parser, ARGUMENT_PLUGIN_NAME, "PlugIn name", String.class); try { final OptionSet options = parser.parse(args); if (options.hasArgument(helpSpec)) { try { parser.printHelpOn(System.out); } catch (final IOException e) { throw new XsdGenRuntimeException(e); } } else { try { final File xmiFile = options.valueOf(xmiFileSpec); final ModelIndex model = new DefaultModelIndex(XmiReader.readModel(xmiFile)); final File documentFile = options.valueOf(documentFileSpec); final PsmConfig<Type> psmConfig = PsmConfigReader.readConfig(documentFile, model); final String plugInName = options.valueOf(plugInNameSpec); final Uml2XsdPlugin plugIn = loadPlugIn(plugInName); final File outFolder = options.valueOf(outFolderSpec); final String outFile = options.valueOf(outFileSpec); final File outLocation = new File(outFolder, outFile); Uml2XsdWriter.writeSchema(psmConfig.getDocuments(), model, plugIn, outLocation); } catch (final FileNotFoundException e) { throw new XsdGenRuntimeException(e); } } } catch (final OptionException e) { LOG.error(e.getMessage()); } catch (final ClassNotFoundException e) { LOG.warn("Unable to load plugin specified in " + ARGUMENT_PLUGIN_NAME + " argument: " + e.getMessage()); } } static void main(final String[] args); }### Answer:
@Test public void testXsdGen() throws IOException { final File outFile = new File("test_sli.xsd"); if (!outFile.exists()) { if (!outFile.createNewFile()) { Assert.fail("failed to create temp file " + outFile.getName()); } } final String folder = getFolder(outFile); final String file = outFile.getName(); final String[] strArr = new String[] { "--documentFile", getAbsPath("test_doc.xml"), "--xmiFile", getAbsPath("test_sli.xmi"), "--plugInName", "org.slc.sli.modeling.tools.xsdgen.PluginForREST", "--outFolder", folder, "--outFile", file }; XsdGen.main(strArr); final URIResolver mockResolver = Mockito.mock(URIResolver.class); final XmlSchema schema = XsdReader.readSchema(outFile.getAbsoluteFile(), mockResolver); Assert.assertNotNull(schema); Assert.assertEquals(2, schema.getElements().getCount()); Assert.assertNotNull(schema.getElementByName("assessmentList")); Assert.assertNotNull(schema.getElementByName("assessment")); outFile.deleteOnExit(); } |
### Question:
Uml2XsdSyntheticHasName implements HasName { @Override public String getName() { final Occurs upperBound = end.getMultiplicity().getRange().getUpper(); final boolean plural = Occurs.UNBOUNDED.equals(upperBound); return adjustPlurality(Uml2XsdTools.camelCase(lookup.getType(end.getType()).getName()), plural); } Uml2XsdSyntheticHasName(final AssociationEnd end, final ModelIndex lookup); @Override String getName(); }### Answer:
@Test public void testGetName() throws Exception { Range range; Multiplicity multiplicity; final Identifier id = Identifier.fromString("1234"); AssociationEnd mockEnd; final ModelIndex mockIndex = Mockito.mock(ModelIndex.class); final Type type = Mockito.mock(Type.class); Uml2XsdSyntheticHasName test; Mockito.when(mockIndex.getType(id)).thenReturn(type); Mockito.when(type.getName()).thenReturn("test"); range = new Range(Occurs.ZERO, Occurs.ONE); multiplicity = new Multiplicity(range); mockEnd = new AssociationEnd(multiplicity, "test", true, id, "test"); test = new Uml2XsdSyntheticHasName(mockEnd, mockIndex); String actual = test.getName(); String expected = "test"; Assert.assertEquals(actual, expected); range = new Range(Occurs.ZERO, Occurs.ZERO); multiplicity = new Multiplicity(range); mockEnd = new AssociationEnd(multiplicity, "test", true, id, "test"); test = new Uml2XsdSyntheticHasName(mockEnd, mockIndex); actual = test.getName(); expected = "test"; Assert.assertEquals(actual, expected); range = new Range(Occurs.ZERO, Occurs.UNBOUNDED); multiplicity = new Multiplicity(range); mockEnd = new AssociationEnd(multiplicity, "test", true, id, "test"); test = new Uml2XsdSyntheticHasName(mockEnd, mockIndex); actual = test.getName(); expected = "tests"; Assert.assertEquals(actual, expected); } |
### Question:
PluginForREST implements Uml2XsdPlugin { @Override public Map<String, String> declarePrefixMappings() { final Map<String, String> pms = new HashMap<String, String>(); if (TARGET_NAMESPACE.trim().length() > 0) { pms.put(TARGET_NAMESPACE_PREFIX, TARGET_NAMESPACE); } return Collections.unmodifiableMap(pms); } @Override Map<String, String> declarePrefixMappings(); @Override QName getElementName(final String name, final boolean isReference); @Override QName getElementType(final String name, final boolean isAssociation); @Override QName getGraphAssociationEndName(final PsmDocument<Type> classType); @Override QName getElementName(final PsmDocument<Type> classType); @Override String getTargetNamespace(); @Override QName getTypeName(final String name); @Override boolean isAttributeFormDefaultQualified(); @Override boolean isElementFormDefaultQualified(); @Override boolean isEnabled(final QName name); @Override void writeAppInfo(final TaggedValue taggedValue, final ModelIndex lookup, final Uml2XsdPluginWriter xsw); @Override void writeAssociation(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeEmbedded(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeReference(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); @Override void writeTopLevelElement(final PsmDocument<Type> classType, final ModelIndex model,
final Uml2XsdPluginWriter xsw); }### Answer:
@Test public void testDeclarePrefixMappings() throws Exception { final Map<String, String> mappings = pluginForREST.declarePrefixMappings(); Assert.assertTrue(mappings.containsKey(TARGET_NAMESPACE_PREFIX)); } |
### Question:
PluginForREST implements Uml2XsdPlugin { @Override public QName getElementName(final String name, final boolean isReference) { return new QName(TARGET_NAMESPACE, Uml2XsdTools.camelCase(name), TARGET_NAMESPACE_PREFIX); } @Override Map<String, String> declarePrefixMappings(); @Override QName getElementName(final String name, final boolean isReference); @Override QName getElementType(final String name, final boolean isAssociation); @Override QName getGraphAssociationEndName(final PsmDocument<Type> classType); @Override QName getElementName(final PsmDocument<Type> classType); @Override String getTargetNamespace(); @Override QName getTypeName(final String name); @Override boolean isAttributeFormDefaultQualified(); @Override boolean isElementFormDefaultQualified(); @Override boolean isEnabled(final QName name); @Override void writeAppInfo(final TaggedValue taggedValue, final ModelIndex lookup, final Uml2XsdPluginWriter xsw); @Override void writeAssociation(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeEmbedded(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeReference(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); @Override void writeTopLevelElement(final PsmDocument<Type> classType, final ModelIndex model,
final Uml2XsdPluginWriter xsw); }### Answer:
@Test public void testGetElementNameQName() throws Exception { final QName expected = new QName(TARGET_NAMESPACE, "myTest", TARGET_NAMESPACE_PREFIX); Assert.assertEquals(expected, pluginForREST.getElementName("MyTest", false)); }
@Test public void testGetElementName() throws Exception { final PsmDocument<Type> doc = new PsmDocument<Type>(Mockito.mock(Type.class), new PsmResource("resource"), new PsmCollection("collection")); final QName expected = new QName(TARGET_NAMESPACE, "collection", TARGET_NAMESPACE_PREFIX); Assert.assertEquals(expected, pluginForREST.getElementName(doc)); } |
### Question:
PluginForREST implements Uml2XsdPlugin { @Override public QName getElementType(final String name, final boolean isAssociation) { return getTypeName(name); } @Override Map<String, String> declarePrefixMappings(); @Override QName getElementName(final String name, final boolean isReference); @Override QName getElementType(final String name, final boolean isAssociation); @Override QName getGraphAssociationEndName(final PsmDocument<Type> classType); @Override QName getElementName(final PsmDocument<Type> classType); @Override String getTargetNamespace(); @Override QName getTypeName(final String name); @Override boolean isAttributeFormDefaultQualified(); @Override boolean isElementFormDefaultQualified(); @Override boolean isEnabled(final QName name); @Override void writeAppInfo(final TaggedValue taggedValue, final ModelIndex lookup, final Uml2XsdPluginWriter xsw); @Override void writeAssociation(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeEmbedded(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeReference(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); @Override void writeTopLevelElement(final PsmDocument<Type> classType, final ModelIndex model,
final Uml2XsdPluginWriter xsw); }### Answer:
@Test public void testGetElementType() throws Exception { final QName expected = new QName(TARGET_NAMESPACE, "MyTest", TARGET_NAMESPACE_PREFIX); Assert.assertEquals(expected, pluginForREST.getElementType("MyTest", false)); } |
### Question:
PluginForREST implements Uml2XsdPlugin { @Override public QName getGraphAssociationEndName(final PsmDocument<Type> classType) { return new QName(TARGET_NAMESPACE, classType.getGraphAssociationEndName().getName(), TARGET_NAMESPACE_PREFIX); } @Override Map<String, String> declarePrefixMappings(); @Override QName getElementName(final String name, final boolean isReference); @Override QName getElementType(final String name, final boolean isAssociation); @Override QName getGraphAssociationEndName(final PsmDocument<Type> classType); @Override QName getElementName(final PsmDocument<Type> classType); @Override String getTargetNamespace(); @Override QName getTypeName(final String name); @Override boolean isAttributeFormDefaultQualified(); @Override boolean isElementFormDefaultQualified(); @Override boolean isEnabled(final QName name); @Override void writeAppInfo(final TaggedValue taggedValue, final ModelIndex lookup, final Uml2XsdPluginWriter xsw); @Override void writeAssociation(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeEmbedded(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeReference(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); @Override void writeTopLevelElement(final PsmDocument<Type> classType, final ModelIndex model,
final Uml2XsdPluginWriter xsw); }### Answer:
@Test public void testGetGraphAssociationEndName() throws Exception { final PsmDocument<Type> doc = new PsmDocument<Type>(Mockito.mock(Type.class), new PsmResource("resource"), new PsmCollection("collection")); final QName expected = new QName(TARGET_NAMESPACE, "resource", TARGET_NAMESPACE_PREFIX); Assert.assertEquals(expected, pluginForREST.getGraphAssociationEndName(doc)); } |
### Question:
ValidationController { public void processZip(File zipFile, ReportStats reportStats) { messageReport.info(reportStats, new FileSource(zipFile.getName()), ValidationMessageCode.VALIDATION_0005, zipFile.getAbsolutePath()); FileResource zipFileResource = new FileResource(zipFile.getAbsolutePath()); String ctlFile = zipFileHandler.handle(zipFileResource, messageReport, reportStats); if (!reportStats.hasErrors()) { processControlFile(zipFile, ctlFile, reportStats); } messageReport.info(reportStats, new FileSource(zipFile.getName()), ValidationMessageCode.VALIDATION_0006, zipFile.getAbsolutePath()); } void doValidation(File path); void processValidators(ControlFile cfile, ReportStats reportStats); void processZip(File zipFile, ReportStats reportStats); void processControlFile(File parentDirectoryOrZipFile, String ctlFile, ReportStats reportStats); Handler<Resource, String> getZipFileHandler(); void setZipFileHandler(Handler<Resource, String> zipFileHandler); ComplexValidator<IngestionFileEntry> getComplexValidator(); void setComplexValidator(ComplexValidator<IngestionFileEntry> complexValidator); Validator<ControlFile> getControlFilevalidator(); void setControlFilevalidator(Validator<ControlFile> controlFilevalidator); AbstractMessageReport getMessageReport(); void setMessageReport(AbstractMessageReport messageReport); }### Answer:
@SuppressWarnings("unchecked") @Test public void testProcessZip() throws IOException, NoSuchFieldException, IllegalAccessException { Handler<org.slc.sli.ingestion.Resource, String> handler = Mockito.mock(Handler.class); ReportStats rs = Mockito.mock(ReportStats.class); Mockito.when(rs.hasErrors()).thenReturn(false); AbstractMessageReport messageReport = Mockito.mock(AbstractMessageReport.class); PrivateAccessor.setField(validationController, "messageReport", messageReport); File zipFile = (new ClassPathResource(zipFileName)).getFile(); FileResource zipFileResource = new FileResource(zipFile.getAbsolutePath()); ValidationController vc = Mockito.spy(validationController); Mockito.doNothing().when(vc).processControlFile(Mockito.any(FileResource.class), Mockito.any(String.class), Mockito.any(ReportStats.class)); Mockito.doReturn(zipFile.getName()).when(handler).handle(zipFileResource, messageReport, rs); vc.setZipFileHandler(handler); vc.processZip(zipFileResource, rs); Mockito.verify(handler, Mockito.atLeastOnce()).handle(zipFileResource, messageReport, rs); } |
### Question:
PluginForREST implements Uml2XsdPlugin { @Override public String getTargetNamespace() { return TARGET_NAMESPACE; } @Override Map<String, String> declarePrefixMappings(); @Override QName getElementName(final String name, final boolean isReference); @Override QName getElementType(final String name, final boolean isAssociation); @Override QName getGraphAssociationEndName(final PsmDocument<Type> classType); @Override QName getElementName(final PsmDocument<Type> classType); @Override String getTargetNamespace(); @Override QName getTypeName(final String name); @Override boolean isAttributeFormDefaultQualified(); @Override boolean isElementFormDefaultQualified(); @Override boolean isEnabled(final QName name); @Override void writeAppInfo(final TaggedValue taggedValue, final ModelIndex lookup, final Uml2XsdPluginWriter xsw); @Override void writeAssociation(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeEmbedded(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); void writeReference(final ClassType complexType, final AssociationEnd end, final ModelIndex model,
final Uml2XsdPluginWriter xsw); @Override void writeTopLevelElement(final PsmDocument<Type> classType, final ModelIndex model,
final Uml2XsdPluginWriter xsw); }### Answer:
@Test public void testGetTargetNamespace() throws Exception { Assert.assertEquals(TARGET_NAMESPACE, pluginForREST.getTargetNamespace()); } |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.