public virtual void TestNoLogs()
        {
            FileUtil.FullyDelete(new FilePath("target/logs"));
            Configuration configuration = GetConfiguration();
            FilePath      f             = new FilePath("target/logs/logs/application_0_0001/container_0_0001_01_000001"
                                                       );

            if (!f.Exists())
            {
                NUnit.Framework.Assert.IsTrue(f.Mkdirs());
            }
            WriteLog(configuration, "admin");
            AggregatedLogsBlockForTest aggregatedBlock = GetAggregatedLogsBlockForTest(configuration
                                                                                       , "admin", "container_0_0001_01_000001");
            ByteArrayOutputStream data        = new ByteArrayOutputStream();
            PrintWriter           printWriter = new PrintWriter(data);
            HtmlBlock             html        = new HtmlBlockForTest();

            HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false);
            aggregatedBlock.Render(block);
            block.GetWriter().Flush();
            string @out = data.ToString();

            NUnit.Framework.Assert.IsTrue(@out.Contains("No logs available for container container_0_0001_01_000001"
                                                        ));
        }
        private AggregatedLogsBlockForTest GetAggregatedLogsBlockForTest(Configuration configuration
                                                                         , string user, string containerId)
        {
            HttpServletRequest request = Org.Mockito.Mockito.Mock <HttpServletRequest>();

            Org.Mockito.Mockito.When(request.GetRemoteUser()).ThenReturn(user);
            AggregatedLogsBlockForTest aggregatedBlock = new AggregatedLogsBlockForTest(configuration
                                                                                        );

            aggregatedBlock.SetRequest(request);
            aggregatedBlock.MoreParams()[YarnWebParams.ContainerId] = containerId;
            aggregatedBlock.MoreParams()[YarnWebParams.NmNodename]  = "localhost:1234";
            aggregatedBlock.MoreParams()[YarnWebParams.AppOwner]    = user;
            aggregatedBlock.MoreParams()["start"] = string.Empty;
            aggregatedBlock.MoreParams()["end"]   = string.Empty;
            aggregatedBlock.MoreParams()[YarnWebParams.EntityString] = "entity";
            return(aggregatedBlock);
        }
        public virtual void TestBadLogs()
        {
            FileUtil.FullyDelete(new FilePath("target/logs"));
            Configuration configuration = GetConfiguration();

            WriteLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001");
            WriteLog(configuration, "owner");
            AggregatedLogsBlockForTest aggregatedBlock = GetAggregatedLogsBlockForTest(configuration
                                                                                       , "admin", "container_0_0001_01_000001");
            ByteArrayOutputStream data        = new ByteArrayOutputStream();
            PrintWriter           printWriter = new PrintWriter(data);
            HtmlBlock             html        = new HtmlBlockForTest();

            HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false);
            aggregatedBlock.Render(block);
            block.GetWriter().Flush();
            string @out = data.ToString();

            NUnit.Framework.Assert.IsTrue(@out.Contains("Logs not available for entity. Aggregation may not be complete, Check back later or try the nodemanager at localhost:1234"
                                                        ));
        }
        public virtual void TestAccessDenied()
        {
            FileUtil.FullyDelete(new FilePath("target/logs"));
            Configuration configuration = GetConfiguration();

            WriteLogs("target/logs/logs/application_0_0001/container_0_0001_01_000001");
            WriteLog(configuration, "owner");
            AggregatedLogsBlockForTest aggregatedBlock = GetAggregatedLogsBlockForTest(configuration
                                                                                       , "owner", "container_0_0001_01_000001");
            ByteArrayOutputStream data        = new ByteArrayOutputStream();
            PrintWriter           printWriter = new PrintWriter(data);
            HtmlBlock             html        = new HtmlBlockForTest();

            HtmlBlock.Block block = new BlockForTest(html, printWriter, 10, false);
            aggregatedBlock.Render(block);
            block.GetWriter().Flush();
            string @out = data.ToString();

            NUnit.Framework.Assert.IsTrue(@out.Contains("User [owner] is not authorized to view the logs for entity"
                                                        ));
        }