Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
restfulapi: add restful Api call to query the lable of a givin file o…
…bject Motivation The patch … has introduced a new feature of adding labels to a file. This patch will provide dCache users with Restful Api call to query file labels. Result The label of a given file object could be queried using the following Restful Api call: curl -v -u http://localhost:3880/api/v1/namespace/public/label1.log\?labels=true Target: master Require-book: yes Require-notes: yes Patch: https://rb.dcache.org/r/13112/ Acked-by: Lea Morschel, Albert Rossi
- Loading branch information
1 parent
e54e3c4
commit 0a1d34d
Showing
9 changed files
with
193 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
modules/dcache-vehicles/src/test/java/org/dcache/vehicles/FileLabelsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
/* | ||
* dCache - http://www.dcache.org/ | ||
* | ||
* Copyright (C) 2021 Deutsches Elektronen-Synchrotron | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.dcache.vehicles; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.Collections; | ||
import java.util.Set; | ||
|
||
import static org.dcache.namespace.FileAttribute.LABELS; | ||
import static org.junit.Assert.*; | ||
|
||
public class FileLabelsTest | ||
{ | ||
FileAttributes fileAttributes; | ||
|
||
@Test | ||
public void shouldNotHaveLabelsInitially() | ||
{ | ||
given(fileAttributes()); | ||
assertFalse(fileAttributes.hasLabel("cat")); | ||
assertFalse(fileAttributes.isDefined(LABELS)); | ||
} | ||
|
||
@Test | ||
public void shouldAllowFetchingLabelsInitially() | ||
{ | ||
given(fileAttributes()); | ||
fileAttributes.getLabels(); | ||
} | ||
|
||
@Test | ||
public void shouldAcceptLabels() | ||
{ | ||
given(fileAttributes().withLabel("dog")); | ||
assertTrue(fileAttributes.isDefined(LABELS)); | ||
assertTrue(fileAttributes.hasLabel("dog")); | ||
assertTrue(fileAttributes.getLabels().contains("dog")); | ||
} | ||
|
||
|
||
@Test | ||
public void checkSetLabels() | ||
{ | ||
Set<String> labels = Set.of("dog", "cat", "yellow"); | ||
given(fileAttributes().withLabels(labels)); | ||
assertEquals(labels, fileAttributes.getLabels()); | ||
} | ||
|
||
private void given(FileAttributesBuilder builder) | ||
{ | ||
fileAttributes = builder.build(); | ||
} | ||
|
||
|
||
private FileAttributesBuilder fileAttributes() | ||
{ | ||
return new FileAttributesBuilder(); | ||
|
||
} | ||
|
||
private static class FileAttributesBuilder | ||
{ | ||
FileAttributes attributes = new FileAttributes(); | ||
public FileAttributesBuilder withLabel(String name) | ||
{ | ||
attributes.setLabels(Collections.singleton(name)); | ||
return this; | ||
} | ||
|
||
|
||
public FileAttributesBuilder withLabels(Set<String> names) | ||
{ | ||
attributes.setLabels(names); | ||
return this; | ||
} | ||
|
||
public FileAttributes build() | ||
{ | ||
return attributes; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters