Github user m4rkmckenna commented on a diff in the pull request:

    https://github.com/apache/brooklyn-server/pull/806#discussion_r135323521
  
    --- Diff: 
core/src/test/java/org/apache/brooklyn/util/core/osgi/OsgisTest.java ---
    @@ -0,0 +1,117 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one
    + * or more contributor license agreements.  See the NOTICE file
    + * distributed with this work for additional information
    + * regarding copyright ownership.  The ASF licenses this file
    + * to you under the Apache License, Version 2.0 (the
    + * "License"); you may not use this file except in compliance
    + * with the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing,
    + * software distributed under the License is distributed on an
    + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    + * KIND, either express or implied.  See the License for the
    + * specific language governing permissions and limitations
    + * under the License.
    + */
    +package org.apache.brooklyn.util.core.osgi;
    +
    +import static org.testng.Assert.assertEquals;
    +
    +import java.util.List;
    +
    +import org.mockito.Mockito;
    +import org.osgi.framework.Bundle;
    +import org.osgi.framework.BundleContext;
    +import org.osgi.framework.Version;
    +import org.osgi.framework.launch.Framework;
    +import org.testng.annotations.BeforeMethod;
    +import org.testng.annotations.Test;
    +
    +import com.google.common.collect.ImmutableList;
    +
    +public class OsgisTest {
    +
    +    private Framework framework;
    +    private BundleContext bundleContext;
    +    private Bundle myBundle1_0_0;
    +    private Bundle myBundle1_1_0;
    +    private Bundle otherBundle1_0_0;
    +    private Bundle snapshotBundle1_0_0_snapshot;
    +    
    +    @BeforeMethod(alwaysRun=true)
    +    public void setUp() throws Exception {
    +        myBundle1_0_0 = Mockito.mock(Bundle.class);
    +        
Mockito.when(myBundle1_0_0.getSymbolicName()).thenReturn("mybundle");
    +        
Mockito.when(myBundle1_0_0.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
    +        
    +        myBundle1_1_0 = Mockito.mock(Bundle.class);
    +        
Mockito.when(myBundle1_1_0.getSymbolicName()).thenReturn("mybundle");
    +        
Mockito.when(myBundle1_1_0.getVersion()).thenReturn(Version.parseVersion("1.1.0"));
    +        
    +        otherBundle1_0_0 = Mockito.mock(Bundle.class);
    +        
Mockito.when(otherBundle1_0_0.getSymbolicName()).thenReturn("otherbundle");
    +        
Mockito.when(otherBundle1_0_0.getVersion()).thenReturn(Version.parseVersion("1.0.0"));
    +        
    +        snapshotBundle1_0_0_snapshot = Mockito.mock(Bundle.class);
    +        
Mockito.when(snapshotBundle1_0_0_snapshot.getSymbolicName()).thenReturn("snapshotbundle");
    +        
Mockito.when(snapshotBundle1_0_0_snapshot.getVersion()).thenReturn(Version.parseVersion("1.0.0.SNAPSHOT"));
    +        
    +        bundleContext = Mockito.mock(BundleContext.class);
    +        Mockito.when(bundleContext.getBundles()).thenReturn(new Bundle[] 
{myBundle1_0_0, myBundle1_1_0, otherBundle1_0_0, snapshotBundle1_0_0_snapshot});
    +        
    +        framework = Mockito.mock(Framework.class);
    +        
Mockito.when(framework.getBundleContext()).thenReturn(bundleContext);
    +        
    +    }
    +    
    +    @Test
    +    public void testFindByNameAndVersion() throws Exception {
    +        Bundle result = Osgis.bundleFinder(framework)
    +                .symbolicName("mybundle")
    +                .version("1.0.0")
    +                .find()
    +                .get();
    +        assertEquals(result, myBundle1_0_0);
    +    }
    +
    +    @Test
    +    public void testFindAllByNameAndVersion() throws Exception {
    +        List<Bundle> result = Osgis.bundleFinder(framework)
    +                .symbolicName("mybundle")
    +                .version("1.0.0")
    +                .findAll();
    +        assertEquals(result, ImmutableList.of(myBundle1_0_0));
    +    }
    +    
    +    @Test
    +    public void testFindByNameAndVersionRange() throws Exception {
    +        List<Bundle> result = Osgis.bundleFinder(framework)
    +                .symbolicName("mybundle")
    +                .version("[1.0.0, 1.1.0)")
    +                .findAll();
    +        assertEquals(result, ImmutableList.of(myBundle1_0_0));
    +        
    +        List<Bundle> result2 = Osgis.bundleFinder(framework)
    +                .symbolicName("mybundle")
    +                .version("[1.0.0, 2.0.0)")
    +                .findAll();
    +        assertEquals(result2, ImmutableList.of(myBundle1_0_0, 
myBundle1_1_0));
    --- End diff --
    
    I think its worth adding the versions `2.0.0.SNAPSHOT` & `2.0.0` and making 
assertions around this boundary
    
    Alos add checks for the range `[1.0.0, 2.0.0]`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---

Reply via email to