@Test public void testBuildBasicRequestWithMock() { WADLGenerator generator = new WADLGenerator(); Mockery mockContext = new Mockery() { { setImposteriser(ClassImposteriser.INSTANCE); } }; final MethodMetadata metadata = mockContext.mock(MethodMetadata.class); final ClassMetadata classMeta = mockContext.mock(ClassMetadata.class); mockContext.checking(new Expectations() { { oneOf(metadata).getFormalParameters(); will(returnValue(null)); } }); Request r = generator.buildRequest(classMeta, metadata); assertNull(r); mockContext.assertIsSatisfied(); }
Request buildRequest(ClassMetadata classMetadata, MethodMetadata metadata) { Request r = null; List<Injectable> params = metadata.getFormalParameters(); if (params != null && params.size() > 0) { if (r == null) { r = new Request(); } boolean hasValidParams = false; List<Param> requestParams = r.getParam(); for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case HEADER: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case ENTITY: hasValidParams = true; Annotation[] anns = p.getAnnotations(); if (anns != null && anns.length > 0) { for (Annotation a : anns) { if (WADLDoc.class.equals(a.annotationType())) { WADLDoc d = (WADLDoc)a; r.getDoc().add(getDocument(d)); } } } Set<Representation> representations = buildIncomingRepresentation(classMetadata, metadata, p); if (representations != null) r.getRepresentation().addAll(representations); break; case COOKIE: break; case FORM: break; case PATH: break; case MATRIX: break; case CONTEXT: break; } } if (!hasValidParams) { r = null; } } return r; }
WADLGenerator { Request buildRequest(ClassMetadata classMetadata, MethodMetadata metadata) { Request r = null; List<Injectable> params = metadata.getFormalParameters(); if (params != null && params.size() > 0) { if (r == null) { r = new Request(); } boolean hasValidParams = false; List<Param> requestParams = r.getParam(); for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case HEADER: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case ENTITY: hasValidParams = true; Annotation[] anns = p.getAnnotations(); if (anns != null && anns.length > 0) { for (Annotation a : anns) { if (WADLDoc.class.equals(a.annotationType())) { WADLDoc d = (WADLDoc)a; r.getDoc().add(getDocument(d)); } } } Set<Representation> representations = buildIncomingRepresentation(classMetadata, metadata, p); if (representations != null) r.getRepresentation().addAll(representations); break; case COOKIE: break; case FORM: break; case PATH: break; case MATRIX: break; case CONTEXT: break; } } if (!hasValidParams) { r = null; } } return r; } }
WADLGenerator { Request buildRequest(ClassMetadata classMetadata, MethodMetadata metadata) { Request r = null; List<Injectable> params = metadata.getFormalParameters(); if (params != null && params.size() > 0) { if (r == null) { r = new Request(); } boolean hasValidParams = false; List<Param> requestParams = r.getParam(); for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case HEADER: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case ENTITY: hasValidParams = true; Annotation[] anns = p.getAnnotations(); if (anns != null && anns.length > 0) { for (Annotation a : anns) { if (WADLDoc.class.equals(a.annotationType())) { WADLDoc d = (WADLDoc)a; r.getDoc().add(getDocument(d)); } } } Set<Representation> representations = buildIncomingRepresentation(classMetadata, metadata, p); if (representations != null) r.getRepresentation().addAll(representations); break; case COOKIE: break; case FORM: break; case PATH: break; case MATRIX: break; case CONTEXT: break; } } if (!hasValidParams) { r = null; } } return r; }  }
WADLGenerator { Request buildRequest(ClassMetadata classMetadata, MethodMetadata metadata) { Request r = null; List<Injectable> params = metadata.getFormalParameters(); if (params != null && params.size() > 0) { if (r == null) { r = new Request(); } boolean hasValidParams = false; List<Param> requestParams = r.getParam(); for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case HEADER: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case ENTITY: hasValidParams = true; Annotation[] anns = p.getAnnotations(); if (anns != null && anns.length > 0) { for (Annotation a : anns) { if (WADLDoc.class.equals(a.annotationType())) { WADLDoc d = (WADLDoc)a; r.getDoc().add(getDocument(d)); } } } Set<Representation> representations = buildIncomingRepresentation(classMetadata, metadata, p); if (representations != null) r.getRepresentation().addAll(representations); break; case COOKIE: break; case FORM: break; case PATH: break; case MATRIX: break; case CONTEXT: break; } } if (!hasValidParams) { r = null; } } return r; }  Application generate(String baseURI, Set<Class<?>> classes); }
WADLGenerator { Request buildRequest(ClassMetadata classMetadata, MethodMetadata metadata) { Request r = null; List<Injectable> params = metadata.getFormalParameters(); if (params != null && params.size() > 0) { if (r == null) { r = new Request(); } boolean hasValidParams = false; List<Param> requestParams = r.getParam(); for (Injectable p : params) { Param param = null; boolean isUnique = true; switch (p.getParamType()) { case QUERY: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case HEADER: hasValidParams = true; param = buildParam(p); for (Param rParam : requestParams) { if (param.getName() != null && param.getName().equals(rParam.getName()) && rParam.getStyle().equals(param.getStyle())) { isUnique = false; } } if (isUnique) { requestParams.add(buildParam(p)); } break; case ENTITY: hasValidParams = true; Annotation[] anns = p.getAnnotations(); if (anns != null && anns.length > 0) { for (Annotation a : anns) { if (WADLDoc.class.equals(a.annotationType())) { WADLDoc d = (WADLDoc)a; r.getDoc().add(getDocument(d)); } } } Set<Representation> representations = buildIncomingRepresentation(classMetadata, metadata, p); if (representations != null) r.getRepresentation().addAll(representations); break; case COOKIE: break; case FORM: break; case PATH: break; case MATRIX: break; case CONTEXT: break; } } if (!hasValidParams) { r = null; } } return r; }  Application generate(String baseURI, Set<Class<?>> classes);  }