/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * guess {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedLoad_Filename_Guess() throws Exception { Repository myrepo = mock( Repository.class ); doReturn( true ).when( myrepo ).isConnected(); doReturn( null ).when( myrepo ).getJobEntryAttributeString( any( ObjectId.class ), anyString() ); doReturn( JOB_ENTRY_FILE_PATH ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "file_name" ); JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.loadRep( myrepo, store, JOB_ENTRY_JOB_OBJECT_ID, databases, servers ); jej.getJobMeta( myrepo, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, myrepo, store, null ); }
@Test public void testBehaviourWithOnlyOrdinaryChecks() throws Exception { final TreeWalker treeWalkerSpy = spy(new TreeWalker()); final Class<?> classAstState = Class.forName("com.puppycrawl.tools.checkstyle.TreeWalker$AstState"); final PackageObjectFactory factory = new PackageObjectFactory( new HashSet<>(), Thread.currentThread().getContextClassLoader()); treeWalkerSpy.configure(createModuleConfig(TypeNameCheck.class)); treeWalkerSpy.setModuleFactory(factory); treeWalkerSpy.setupChild(createModuleConfig(TypeNameCheck.class)); final File file = temporaryFolder.newFile("file.java"); final List<String> lines = new ArrayList<>(); lines.add("class Test {}"); treeWalkerSpy.processFiltered(file, new FileText(file, lines)); verifyPrivate(treeWalkerSpy, times(1)).invoke("walk", any(DetailAST.class), any(FileContents.class), any(classAstState)); verifyPrivate(treeWalkerSpy, times(0)).invoke("getFilteredMessages", any(String.class), any(FileContents.class), any(DetailAST.class)); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * keep {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedLoad_Filename() throws Exception { Repository myrepo = mock( Repository.class ); doReturn( true ).when( myrepo ).isConnected(); doReturn( null ).when( myrepo ).getJobEntryAttributeString( any( ObjectId.class ), anyString() ); doReturn( "filename" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "specification_method" ); doReturn( JOB_ENTRY_FILE_PATH ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "file_name" ); JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.loadRep( myrepo, store, JOB_ENTRY_JOB_OBJECT_ID, databases, servers ); jej.getJobMeta( myrepo, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, myrepo, store, null ); }
@Test public void testBehaviourWithOnlyCommentChecks() throws Exception { final TreeWalker treeWalkerSpy = spy(new TreeWalker()); final Class<?> classAstState = Class.forName("com.puppycrawl.tools.checkstyle.TreeWalker$AstState"); final PackageObjectFactory factory = new PackageObjectFactory( new HashSet<>(), Thread.currentThread().getContextClassLoader()); treeWalkerSpy.configure(createModuleConfig(CommentsIndentationCheck.class)); treeWalkerSpy.setModuleFactory(factory); treeWalkerSpy.setupChild(createModuleConfig(CommentsIndentationCheck.class)); final File file = temporaryFolder.newFile("file.java"); final List<String> lines = new ArrayList<>(); lines.add("class Test {}"); treeWalkerSpy.processFiltered(file, new FileText(file, lines)); verifyPrivate(treeWalkerSpy, times(1)).invoke("walk", any(DetailAST.class), any(FileContents.class), any(classAstState)); verifyPrivate(treeWalkerSpy, times(0)).invoke("getFilteredMessages", any(String.class), any(FileContents.class), any(DetailAST.class)); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by name, * keep {@link ObjectLocationSpecificationMethod} as {@code REPOSITORY_BY_NAME}. * Load the job from the repository using the specified job name and directory. */ @Test public void testConnectedLoad_RepByName_HDFS() throws Exception { Repository myrepo = mock( Repository.class ); doReturn( true ).when( myrepo ).isConnected(); doReturn( null ).when( myrepo ).getJobEntryAttributeString( any( ObjectId.class ), anyString() ); doReturn( "rep_name" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "specification_method" ); doReturn( "job" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "name" ); doReturn( "${hdfs}" ).when( myrepo ).getJobEntryAttributeString( JOB_ENTRY_JOB_OBJECT_ID, "dir_path" ); JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.loadRep( myrepo, store, JOB_ENTRY_JOB_OBJECT_ID, databases, servers ); jej.getJobMeta( myrepo, store, space ); assertEquals( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, "hdfs://server/path/job.kjb", myrepo, store, null ); }
@Test public void testSetOption() throws Exception { int optId = 1; Object option = new Object(); sniffySocket.setOption(optId, option); verifyPrivate(delegate).invoke("setOption", optId, option); verifyNoMoreInteractions(delegate); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * guess {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedImport_Filename_Guess() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setFileName( JOB_ENTRY_FILE_PATH ); jej.loadXML( getNode( jej ), databases, servers, repository, store ); jej.getJobMeta( repository, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, repository, store, null ); }
@Test public void testSetPerformancePreferences() throws Exception { sniffySocket.setPerformancePreferences(1, 2, 3); verifyPrivate(delegate).invoke("setPerformancePreferences", 1, 2, 3); verifyNoMoreInteractions(delegate); }
/** * When disconnected from the repository and {@link JobEntryJob} references a child job by file path, * {@link ObjectLocationSpecificationMethod} will be {@code FILENAME}. */ @Test public void testNotConnectedLoad_Filename() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME ); jej.setFileName( JOB_ENTRY_FILE_PATH ); jej.loadXML( getNode( jej ), databases, servers, null, store ); jej.getJobMeta( null, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, null, store, null ); }
@Test public void testSendUrgentData() throws Exception { sniffySocket.sendUrgentData(1); // TODO: insert timeout here and to similar methods? verifyPrivate(delegate).invoke("sendUrgentData",1); verifyNoMoreInteractions(delegate); }
/** * When disconnected from the repository and {@link JobEntryJob} references a child job by {@link ObjectId}, * this reference will be invalid to run such job. * Default to {@link ObjectLocationSpecificationMethod}.{@code FILENAME} with a {@code null} file path. */ @Test public void testNotConnectedLoad_RepByRef() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.REPOSITORY_BY_REFERENCE ); jej.setJobObjectId( JOB_ENTRY_JOB_OBJECT_ID ); jej.loadXML( getNode( jej ), databases, servers, null, store ); jej.getJobMeta( null, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, null, null, store, null ); }
@Test public void testShutdownInput() throws Exception { sniffySocket.shutdownInput(); verifyPrivate(delegate).invoke("shutdownInput"); verifyNoMoreInteractions(delegate); }
/** * When connected to the repository and {@link JobEntryJob} references a child job by file path, * keep {@link ObjectLocationSpecificationMethod} as {@code FILENAME}. * Load the job from the repository using the specified file path. */ @Test public void testConnectedImport_Filename() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME ); jej.setFileName( JOB_ENTRY_FILE_PATH ); jej.loadXML( getNode( jej ), databases, servers, repository, store ); jej.getJobMeta( repository, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, JOB_ENTRY_FILE_PATH, repository, store, null ); }
@Test public void testShutdownOutput() throws Exception { sniffySocket.shutdownOutput(); verifyPrivate(delegate).invoke("shutdownOutput"); verifyNoMoreInteractions(delegate); }
/** * When disconnected from the repository and {@link JobEntryJob} references a child job by name, * this reference will be invalid to run such job. * Default to {@link ObjectLocationSpecificationMethod}.{@code FILENAME} with a {@code null} file path. */ @Test public void testNotConnectedLoad_RepByName() throws Exception { JobEntryJob jej = spy( new JobEntryJob( JOB_ENTRY_JOB_NAME ) ); jej.setSpecificationMethod( ObjectLocationSpecificationMethod.REPOSITORY_BY_NAME ); jej.setJobName( JOB_ENTRY_FILE_NAME ); jej.setDirectory( JOB_ENTRY_FILE_DIRECTORY ); jej.loadXML( getNode( jej ), databases, servers, null, store ); jej.getJobMeta( null, store, space ); assertEquals( ObjectLocationSpecificationMethod.FILENAME, jej.getSpecificationMethod() ); verifyNew( JobMeta.class ).withArguments( space, null, null, store, null ); }
@Test public void testCreate() throws Exception { sniffySocket.create(true); verifyPrivate(delegate).invoke("create", true); verifyNoMoreInteractions(delegate); }
@Test public void testClose() throws Exception { sniffySocket.close(); verifyPrivate(delegate).invoke("close"); verifyNoMoreInteractions(delegate); }
@Test public void testConnect() throws Exception { sniffySocket.connect("localhost", 123); verifyPrivate(delegate).invoke("connect", "localhost", 123); verifyNoMoreInteractions(delegate); }
@Test public void testListen() throws Exception { sniffySocket.listen(123); verifyPrivate(delegate).invoke("listen", 123); verifyNoMoreInteractions(delegate); }
@Test public void testAccept() throws Exception { SocketImpl socketImpl = new SnifferSocketImpl(null); sniffySocket.accept(socketImpl); verifyPrivate(delegate).invoke("accept", socketImpl); verifyNoMoreInteractions(delegate); }