/** * Find the first job in the list that comes to mind! * * @param jobName * @return the first transformation with the specified name */ public synchronized Job getJob( String jobName ) { for ( CarteObjectEntry entry : jobMap.keySet() ) { if ( entry.getName().equals( jobName ) ) { return getJob( entry ); } } return null; }
@Override public Object doCall() throws Exception { while ( condition.get() ) { int i = random.nextInt( INITIAL_JOB_MAP_SIZE ); CarteObjectEntry entry = jobMap.getJobObjects().get( i ); if ( entry == null ) { throw new IllegalStateException( String.format( "Returned CarteObjectEntry must not be null. EntryId = %d", i ) ); } final String jobName = JOB_NAME_STRING + i; Job job = jobMap.getJob( entry.getName() ); if ( job == null ) { throw new IllegalStateException( String.format( "Returned job must not be null. Job name = %s", jobName ) ); } JobConfiguration jobConfiguration = jobMap.getConfiguration( entry.getName() ); if ( jobConfiguration == null ) { throw new IllegalStateException( String.format( "Returned jobConfiguration must not be null. Job name = %s", jobName ) ); } } return null; } }
@Override public int compare( CarteObjectEntry o1, CarteObjectEntry o2 ) { Job t1 = getJobMap().getJob( o1 ); Job t2 = getJobMap().getJob( o2 ); Date d1 = t1.getLogDate(); Date d2 = t2.getLogDate(); // if both jobs have last log date, desc sort by log date if ( d1 != null && d2 != null ) { int logDateCompare = d2.compareTo( d1 ); if ( logDateCompare != 0 ) { return logDateCompare; } } return o1.compareTo( o2 ); } };
public static Job getJob( String id ) { return CarteSingleton.getInstance().getJobMap().getJob( getCarteObjectEntry( id ) ); }
Job job = getJobMap().getJob( entry ); String status = job.getStatus(); SlaveServerJobStatus jobStatus = new SlaveServerJobStatus( entry.getName(), entry.getId(), status ); String name = jobEntries.get( i ).getName(); String id = jobEntries.get( i ).getId(); Job job = getJobMap().getJob( jobEntries.get( i ) ); String status = job.getStatus(); String trClass = evenRow ? "cellTableEvenRow" : "cellTableOddRow"; // alternating row color
@Test @PrepareForTest( { Encode.class } ) public void testStopJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); mockJob.setName( ServletTestUtils.BAD_STRING_TO_TEST ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( StopJobServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); when( mockJob.getLogChannelId() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); stopJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); } }
@Test @PrepareForTest( { Encode.class } ) public void testRemoveJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); mockJob.setName( ServletTestUtils.BAD_STRING_TO_TEST ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( RemoveJobServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); when( mockJob.getLogChannelId() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); removeJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H3", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); } }
@Test @PrepareForTest( { Encode.class } ) public void testStartJobServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); mockJob.setName( ServletTestUtils.BAD_STRING_TO_TEST ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( StartJobServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); when( mockJob.getLogChannelId() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); startJobServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( ServletTestUtils.hasBadText( ServletTestUtils.getInsideOfTag( "H1", out.toString() ) ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); } }
@Test @PrepareForTest( { Encode.class, Job.class } ) public void testGetJobStatusServletEscapesHtmlWhenTransFound() throws ServletException, IOException { KettleLogStore.init(); HttpServletRequest mockHttpServletRequest = mock( HttpServletRequest.class ); HttpServletResponse mockHttpServletResponse = mock( HttpServletResponse.class ); Job mockJob = PowerMockito.mock( Job.class ); JobMeta mockJobMeta = mock( JobMeta.class ); LogChannelInterface mockLogChannelInterface = mock( LogChannelInterface.class ); StringWriter out = new StringWriter(); PrintWriter printWriter = new PrintWriter( out ); PowerMockito.spy( Encode.class ); when( mockHttpServletRequest.getContextPath() ).thenReturn( GetJobStatusServlet.CONTEXT_PATH ); when( mockHttpServletRequest.getParameter( anyString() ) ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); when( mockHttpServletResponse.getWriter() ).thenReturn( printWriter ); when( mockJobMap.getJob( any( CarteObjectEntry.class ) ) ).thenReturn( mockJob ); PowerMockito.when( mockJob.getJobname() ).thenReturn( ServletTestUtils.BAD_STRING_TO_TEST ); PowerMockito.when( mockJob.getLogChannel() ).thenReturn( mockLogChannelInterface ); PowerMockito.when( mockJob.getJobMeta() ).thenReturn( mockJobMeta ); PowerMockito.when( mockJobMeta.getMaximum() ).thenReturn( new Point( 10, 10 ) ); getJobStatusServlet.doGet( mockHttpServletRequest, mockHttpServletResponse ); assertFalse( out.toString().contains( ServletTestUtils.BAD_STRING_TO_TEST ) ); PowerMockito.verifyStatic( atLeastOnce() ); Encode.forHtml( anyString() ); }