AttributeDelegator extends BaseDelegator implements IAttributeDelegator { @Override public List<IFileSpec> setFileAttributes( final List<IFileSpec> files, @Nonnull final Map<String, String> attributes, final SetFileAttributesOptions opts) throws P4JavaException { Validate.notNull(attributes); List<String> args = new ArrayList<>(); for (String name : attributes.keySet()) { args.add("-n" + name); } for (Map.Entry<String, String> entry : attributes.entrySet()) { if (isNotBlank(entry.getValue())) { args.add("-v" + entry.getValue()); } } List<Map<String, Object>> resultMaps = execMapCmdList( ATTRIBUTE, processParameters( opts, files, args.toArray(new String[args.size()]), true, server), null); return buildSetFileAttributesFileSpecsFromCommandResultMaps( resultMaps, rethrowFunction( new FunctionWithException<Map<String, Object>, IFileSpec>() { @Override public IFileSpec apply(Map<String, Object> map) throws P4JavaException { return ResultListBuilder.handleFileReturn(map, server); } } ) ); } AttributeDelegator(IOptionsServer server); @Override List<IFileSpec> setFileAttributes(
            final List<IFileSpec> files,
            @Nonnull final Map<String, String> attributes,
            final SetFileAttributesOptions opts); @Override List<IFileSpec> setFileAttributes(
            final List<IFileSpec> files,
            @Nonnull final String attributeName,
            @Nonnull final InputStream inStream,
            final SetFileAttributesOptions opts);  }
@Test public void testNormalBehaviour() throws P4JavaException { givenInfoMessageCode(); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); List<IFileSpec> actualFileSpecs = attributeDelegator.setFileAttributes( fileSpecs, createTestAttributes(), mockOpts); assertThat(actualFileSpecs.size(), is(1)); assertThat(actualFileSpecs.get(0).getStatusString(), is(STREAM_NAME)); }
@Test public void testNullStream() throws P4JavaException { assertThrows(NullPointerException.class, () -> attributeDelegator.setFileAttributes(fileSpecs, "owner", null, mockOpts)); }
@Test public void testP4ExceptionPropagation() throws P4JavaException { thrown.expect(AccessException.AccessExceptionForTests.class); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), eq(null))) .thenThrow(AccessException.AccessExceptionForTests.class); attributeDelegator.setFileAttributes(fileSpecs, createTestAttributes(), mockOpts); }
@Test public void testStreamNormalBehaviour() throws P4JavaException { givenInfoMessageCode(); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), any(Map.class))) .thenReturn(resultMaps); List<IFileSpec> actualFileSpecs = attributeDelegator.setFileAttributes(fileSpecs, "owner", mockInputStream, mockOpts); assertThat(actualFileSpecs.size(), is(1)); assertThat(actualFileSpecs.get(0).getStatusString(), is(STREAM_NAME)); }
@Test public void testStreamP4JavaPropagation() throws P4JavaException { thrown.expect(AccessException.class); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), any(Map.class))) .thenThrow(AccessException.AccessExceptionForTests.class); attributeDelegator.setFileAttributes(fileSpecs, "owner", mockInputStream, mockOpts); }
@Test public void testNormalBehaviour() throws P4JavaException { givenInfoMessageCode(); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), eq((Map<String,Object>)null))) .thenReturn(resultMaps); List<IFileSpec> actualFileSpecs = attributeDelegator.setFileAttributes( fileSpecs, createTestAttributes(), mockOpts); Assert.assertEquals(1, actualFileSpecs.size()); Assert.assertEquals(STREAM_NAME, actualFileSpecs.get(0).getStatusMessage()); }
@Test(expected=NullPointerException.class) public void testNullStream() throws P4JavaException { attributeDelegator.setFileAttributes(fileSpecs, "owner", null, mockOpts); }
@Test public void testP4ExceptionPropagation() throws P4JavaException { thrown.expect(AccessException.class); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), eq((Map<String,Object>)null))) .thenThrow(AccessException.class); attributeDelegator.setFileAttributes(fileSpecs, createTestAttributes(), mockOpts); }
@SuppressWarnings("unchecked") @Test public void testStreamNormalBehaviour() throws P4JavaException { givenInfoMessageCode(); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), any(Map.class))) .thenReturn(resultMaps); List<IFileSpec> actualFileSpecs = attributeDelegator.setFileAttributes(fileSpecs, "owner", mockInputStream, mockOpts); Assert.assertEquals(1, actualFileSpecs.size()); Assert.assertEquals(STREAM_NAME, actualFileSpecs.get(0).getStatusMessage()); }
@SuppressWarnings("unchecked") @Test public void testStreamP4JavaPropagation() throws P4JavaException { thrown.expect(AccessException.class); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), any(Map.class))) .thenThrow(AccessException.class); attributeDelegator.setFileAttributes(fileSpecs, "owner", mockInputStream, mockOpts); }
@Test public void testNormalBehaviour() throws P4JavaException { givenInfoMessageCode(); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), eq(null))) .thenReturn(resultMaps); List<IFileSpec> actualFileSpecs = attributeDelegator.setFileAttributes( fileSpecs, createTestAttributes(), mockOpts); assertThat(actualFileSpecs.size(), is(1)); assertThat(actualFileSpecs.get(0).getStatusMessage(), is(STREAM_NAME)); }
@Test public void testNullAttribute() throws P4JavaException { thrown.expect(NullPointerException.class); attributeDelegator.setFileAttributes(fileSpecs, null, mockOpts); }
@Test public void testNullStream() throws P4JavaException { expectThrows(NullPointerException.class, () -> attributeDelegator.setFileAttributes(fileSpecs, "owner", null, mockOpts)); }
@Test public void testP4ExceptionPropagation() throws P4JavaException { thrown.expect(AccessException.class); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), eq(null))) .thenThrow(AccessException.class); attributeDelegator.setFileAttributes(fileSpecs, createTestAttributes(), mockOpts); }
@Test public void testStreamEmptyAttributeName() throws P4JavaException { thrown.expect(IllegalArgumentException.class); attributeDelegator.setFileAttributes(fileSpecs, EMPTY, mockInputStream, mockOpts); }
@Test public void testStreamNormalBehaviour() throws P4JavaException { givenInfoMessageCode(); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), any(Map.class))) .thenReturn(resultMaps); List<IFileSpec> actualFileSpecs = attributeDelegator.setFileAttributes(fileSpecs, "owner", mockInputStream, mockOpts); assertThat(actualFileSpecs.size(), is(1)); assertThat(actualFileSpecs.get(0).getStatusMessage(), is(STREAM_NAME)); }
@Test public void testStreamP4JavaPropagation() throws P4JavaException { thrown.expect(AccessException.class); when(server.execMapCmdList(eq(ATTRIBUTE.toString()), any(String[].class), any(Map.class))) .thenThrow(AccessException.class); attributeDelegator.setFileAttributes(fileSpecs, "owner", mockInputStream, mockOpts); }