@Test public void testReadAs() throws Exception { URLStreamProvider streamProvider = createNiceMock(URLStreamProvider.class); HttpURLConnection urlConnection = createNiceMock(HttpURLConnection.class); InputStream inputStream = createNiceMock(InputStream.class); ViewContext viewContext = createNiceMock(ViewContext.class); Map<String, String> headers = new HashMap<String, String>(); headers.put("header", "headerValue"); Map<String, List<String>> headerMap = new HashMap<String, List<String>>(); headerMap.put("header", Collections.singletonList("headerValue")); expect(streamProvider.processURL(eq("spec?doAs=joe"), eq("requestMethod"), aryEq("params".getBytes()), eq(headerMap))).andReturn(urlConnection); expect(urlConnection.getInputStream()).andReturn(inputStream); replay(streamProvider, urlConnection, inputStream); ViewURLStreamProvider viewURLStreamProvider = new ViewURLStreamProvider(viewContext, streamProvider); Assert.assertEquals(inputStream, viewURLStreamProvider.readAs("spec", "requestMethod", "params", headers, "joe")); verify(streamProvider, urlConnection, inputStream); }
@Override public InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers, String userName) throws IOException { return readFrom(addDoAs(spec, userName), requestMethod, body, headers); }
ViewURLStreamProvider implements org.apache.ambari.view.URLStreamProvider, URLConnectionProvider { @Override public InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers, String userName) throws IOException { return readFrom(addDoAs(spec, userName), requestMethod, body, headers); } }
ViewURLStreamProvider implements org.apache.ambari.view.URLStreamProvider, URLConnectionProvider { @Override public InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers, String userName) throws IOException { return readFrom(addDoAs(spec, userName), requestMethod, body, headers); } protected  ViewURLStreamProvider(ViewContext viewContext, URLStreamProvider streamProvider); }
ViewURLStreamProvider implements org.apache.ambari.view.URLStreamProvider, URLConnectionProvider { @Override public InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers, String userName) throws IOException { return readFrom(addDoAs(spec, userName), requestMethod, body, headers); } protected  ViewURLStreamProvider(ViewContext viewContext, URLStreamProvider streamProvider); @Override InputStream readFrom(String spec, String requestMethod, String body, Map<String, String> headers); @Override InputStream readFrom(String spec, String requestMethod, InputStream body, Map<String, String> headers); @Override InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers,
                            String userName); @Override InputStream readAs(String spec, String requestMethod, InputStream body, Map<String, String> headers,
                            String userName); @Override InputStream readAsCurrent(String spec, String requestMethod, String body, Map<String, String> headers); @Override InputStream readAsCurrent(String spec, String requestMethod, InputStream body, Map<String, String> headers); @Override HttpURLConnection getConnection(String spec,
                                         String requestMethod,
                                         String body,
                                         Map<String, String> headers); @Override HttpURLConnection getConnection(String spec,
                                         String requestMethod,
                                         InputStream body,
                                         Map<String, String> headers); @Override HttpURLConnection getConnectionAs(String spec,
                                           String requestMethod,
                                           String body,
                                           Map<String, String> headers,
                                           String userName); @Override HttpURLConnection getConnectionAs(String spec,
                                           String requestMethod,
                                           InputStream body,
                                           Map<String, String> headers,
                                           String userName); @Override HttpURLConnection getConnectionAsCurrent(String spec,
                                                  String requestMethod,
                                                  String body,
                                                  Map<String, String> headers); @Override HttpURLConnection getConnectionAsCurrent(String spec,
                                                  String requestMethod,
                                                  InputStream body,
                                                  Map<String, String> headers); }
ViewURLStreamProvider implements org.apache.ambari.view.URLStreamProvider, URLConnectionProvider { @Override public InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers, String userName) throws IOException { return readFrom(addDoAs(spec, userName), requestMethod, body, headers); } protected  ViewURLStreamProvider(ViewContext viewContext, URLStreamProvider streamProvider); @Override InputStream readFrom(String spec, String requestMethod, String body, Map<String, String> headers); @Override InputStream readFrom(String spec, String requestMethod, InputStream body, Map<String, String> headers); @Override InputStream readAs(String spec, String requestMethod, String body, Map<String, String> headers,
                            String userName); @Override InputStream readAs(String spec, String requestMethod, InputStream body, Map<String, String> headers,
                            String userName); @Override InputStream readAsCurrent(String spec, String requestMethod, String body, Map<String, String> headers); @Override InputStream readAsCurrent(String spec, String requestMethod, InputStream body, Map<String, String> headers); @Override HttpURLConnection getConnection(String spec,
                                         String requestMethod,
                                         String body,
                                         Map<String, String> headers); @Override HttpURLConnection getConnection(String spec,
                                         String requestMethod,
                                         InputStream body,
                                         Map<String, String> headers); @Override HttpURLConnection getConnectionAs(String spec,
                                           String requestMethod,
                                           String body,
                                           Map<String, String> headers,
                                           String userName); @Override HttpURLConnection getConnectionAs(String spec,
                                           String requestMethod,
                                           InputStream body,
                                           Map<String, String> headers,
                                           String userName); @Override HttpURLConnection getConnectionAsCurrent(String spec,
                                                  String requestMethod,
                                                  String body,
                                                  Map<String, String> headers); @Override HttpURLConnection getConnectionAsCurrent(String spec,
                                                  String requestMethod,
                                                  InputStream body,
                                                  Map<String, String> headers);  }