public virtual void TestNodeAppsUserEmpty()
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            AddAppContainers(app);
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp("foo", 1234, 2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            try
            {
                r.Path("ws").Path("v1").Path("node").Path("apps").QueryParam("user", string.Empty
                                                                             ).Accept(MediaType.ApplicationJson).Get <JSONObject>();
                NUnit.Framework.Assert.Fail("should have thrown exception on invalid user query");
            }
            catch (UniformInterfaceException ue)
            {
                ClientResponse response = ue.GetResponse();
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus
                                                    ());
                NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                                );
                JSONObject msg       = response.GetEntity <JSONObject>();
                JSONObject exception = msg.GetJSONObject("RemoteException");
                NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length
                                                    ());
                string message   = exception.GetString("message");
                string type      = exception.GetString("exception");
                string classname = exception.GetString("javaClassName");
                WebServicesTestUtils.CheckStringMatch("exception message", "java.lang.Exception: Error: You must specify a non-empty string for the user"
                                                      , message);
                WebServicesTestUtils.CheckStringMatch("exception type", "BadRequestException", type
                                                      );
                WebServicesTestUtils.CheckStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.BadRequestException"
                                                      , classname);
            }
        }
        public virtual void TestSingleContainerWrong()
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            AddAppContainers(app);
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp(2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            try
            {
                r.Path("ws").Path("v1").Path("node").Path("containers").Path("container_1234_0001_01_000005"
                                                                             ).Accept(MediaType.ApplicationJson).Get <JSONObject>();
                NUnit.Framework.Assert.Fail("should have thrown exception on invalid user query");
            }
            catch (UniformInterfaceException ue)
            {
                ClientResponse response = ue.GetResponse();
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.NotFound, response.GetClientResponseStatus
                                                    ());
                NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                                );
                JSONObject msg       = response.GetEntity <JSONObject>();
                JSONObject exception = msg.GetJSONObject("RemoteException");
                NUnit.Framework.Assert.AreEqual("incorrect number of elements", 3, exception.Length
                                                    ());
                string message   = exception.GetString("message");
                string type      = exception.GetString("exception");
                string classname = exception.GetString("javaClassName");
                WebServicesTestUtils.CheckStringMatch("exception message", "java.lang.Exception: container with id, container_1234_0001_01_000005, not found"
                                                      , message);
                WebServicesTestUtils.CheckStringMatch("exception type", "NotFoundException", type
                                                      );
                WebServicesTestUtils.CheckStringMatch("exception classname", "org.apache.hadoop.yarn.webapp.NotFoundException"
                                                      , classname);
            }
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestNodeSingleAppHelper(string media)
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            Dictionary <string, string> hash = AddAppContainers(app);

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp(2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("apps").Path(
                app.GetAppId().ToString()).Accept(media).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            VerifyNodeAppInfo(json.GetJSONObject("app"), app, hash);
        }
        public virtual void TestNodeAppsUserNone()
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            AddAppContainers(app);
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp("foo", 1234, 2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("apps").QueryParam
                                          ("user", "george").Accept(MediaType.ApplicationJson).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();

            NUnit.Framework.Assert.AreEqual("apps is not null", JSONObject.Null, json.Get("apps"
                                                                                          ));
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestNodeHelper(string path, string media)
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            Dictionary <string, string> hash = AddAppContainers(app);

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp(2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            Dictionary <string, string> hash2 = AddAppContainers(app2);
            ClientResponse response           = r.Path("ws").Path("v1").Path("node").Path(path).Accept(
                media).Get <ClientResponse>();

            NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                            );
            JSONObject json = response.GetEntity <JSONObject>();
            JSONObject info = json.GetJSONObject("apps");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 1, info.Length());
            JSONArray appInfo = info.GetJSONArray("app");

            NUnit.Framework.Assert.AreEqual("incorrect number of elements", 2, appInfo.Length
                                                ());
            string id = appInfo.GetJSONObject(0).GetString("id");

            if (id.Matches(app.GetAppId().ToString()))
            {
                VerifyNodeAppInfo(appInfo.GetJSONObject(0), app, hash);
                VerifyNodeAppInfo(appInfo.GetJSONObject(1), app2, hash2);
            }
            else
            {
                VerifyNodeAppInfo(appInfo.GetJSONObject(0), app2, hash2);
                VerifyNodeAppInfo(appInfo.GetJSONObject(1), app, hash);
            }
        }
        public virtual void TestNodeAppsStateInvalidXML()
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            AddAppContainers(app);
            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp("foo", 1234, 2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            try
            {
                r.Path("ws").Path("v1").Path("node").Path("apps").QueryParam("state", "FOO_STATE"
                                                                             ).Accept(MediaType.ApplicationXml).Get <JSONObject>();
                NUnit.Framework.Assert.Fail("should have thrown exception on invalid user query");
            }
            catch (UniformInterfaceException ue)
            {
                ClientResponse response = ue.GetResponse();
                NUnit.Framework.Assert.AreEqual(ClientResponse.Status.BadRequest, response.GetClientResponseStatus
                                                    ());
                NUnit.Framework.Assert.AreEqual(MediaType.ApplicationXmlType, response.GetType());
                string msg = response.GetEntity <string>();
                DocumentBuilderFactory dbf = DocumentBuilderFactory.NewInstance();
                DocumentBuilder        db  = dbf.NewDocumentBuilder();
                InputSource            @is = new InputSource();
                @is.SetCharacterStream(new StringReader(msg));
                Document dom       = db.Parse(@is);
                NodeList nodes     = dom.GetElementsByTagName("RemoteException");
                Element  element   = (Element)nodes.Item(0);
                string   message   = WebServicesTestUtils.GetXmlString(element, "message");
                string   type      = WebServicesTestUtils.GetXmlString(element, "exception");
                string   classname = WebServicesTestUtils.GetXmlString(element, "javaClassName");
                VerifyStateInvalidException(message, type, classname);
            }
        }
        /// <exception cref="Org.Codehaus.Jettison.Json.JSONException"/>
        /// <exception cref="System.Exception"/>
        public virtual void TestNodeSingleContainersHelper(string media)
        {
            WebResource r = Resource();

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app = new MockApp(1);
            nmContext.GetApplications()[app.GetAppId()] = app;
            Dictionary <string, string> hash = AddAppContainers(app);

            Org.Apache.Hadoop.Yarn.Server.Nodemanager.Containermanager.Application.Application
                app2 = new MockApp(2);
            nmContext.GetApplications()[app2.GetAppId()] = app2;
            AddAppContainers(app2);
            foreach (string id in hash.Keys)
            {
                ClientResponse response = r.Path("ws").Path("v1").Path("node").Path("containers")
                                          .Path(id).Accept(media).Get <ClientResponse>();
                NUnit.Framework.Assert.AreEqual(MediaType.ApplicationJsonType, response.GetType()
                                                );
                JSONObject json = response.GetEntity <JSONObject>();
                VerifyNodeContainerInfo(json.GetJSONObject("container"), nmContext.GetContainers(
                                            )[ConverterUtils.ToContainerId(id)]);
            }
        }