DescribableModel implements Serializable { @SuppressWarnings("unchecked") public static UninstantiatedDescribable uninstantiate2_(Object o) { return new DescribableModel(o.getClass()).uninstantiate2(o); } DescribableModel(Class<T> clazz); static DescribableModel<T> of(Class<T> clazz); Class<T> getType(); Collection<DescribableParameter> getParameters(); DescribableParameter getParameter(String name); boolean hasSingleRequiredParameter(); @CheckForNull DescribableParameter getSoleRequiredParameter(); @CheckForNull DescribableParameter getFirstRequiredParameter(); String getDisplayName(); @Deprecated T instantiate(Map<String,?> arguments); T instantiate(Map<String,?> arguments, @CheckForNull TaskListener listener); Map<String,Object> uninstantiate(T o); UninstantiatedDescribable uninstantiate2(T o); static Map<String,Object> uninstantiate_(Object o); @SuppressWarnings("unchecked") static UninstantiatedDescribable uninstantiate2_(Object o); boolean isDeprecated(); @CheckForNull String getHelp(); @Override String toString(); @SuppressFBWarnings("MS_SHOULD_BE_FINAL") // Used to control warnings that instantiate parameters will be ignored
    @Restricted(NoExternalUse.class)
    static boolean STRICT_PARAMETER_CHECKING; static final String CLAZZ; }
@Issue("JENKINS-43337") @Test public void ambiguousSimpleName() throws Exception { AmbiguousContainer container = new AmbiguousContainer(new FirstAmbiguous.CommonName("first"), new UnambiguousClassName("second")); UninstantiatedDescribable ud = DescribableModel.uninstantiate2_(container); Object o = ud.toMap().get("ambiguous"); assertTrue(o instanceof Map); Map<String,Object> m = (Map<String,Object>)o; assertEquals(FirstAmbiguous.CommonName.class.getName(), m.get("$class")); Object o2 = ud.toMap().get("unambiguous"); assertTrue(o2 instanceof Map); Map<String,Object> m2 = (Map<String,Object>)o2; assertEquals(UnambiguousClassName.class.getSimpleName(), m2.get("$class")); }
@Issue("JENKINS-45130") @Test public void ambiguousTopLevelSimpleName() throws Exception { AmbiguousContainer container = new AmbiguousContainer(new SharedName("first"), new UnambiguousClassName("second")); UninstantiatedDescribable ud = DescribableModel.uninstantiate2_(container); Object o = ud.toMap().get("ambiguous"); assertTrue(o instanceof Map); Map<String,Object> m = (Map<String,Object>)o; assertEquals(SharedName.class.getName(), m.get("$class")); Object o2 = ud.toMap().get("unambiguous"); assertTrue(o2 instanceof Map); Map<String,Object> m2 = (Map<String,Object>)o2; assertEquals(UnambiguousClassName.class.getSimpleName(), m2.get("$class")); }
@Test @Issue("JENKINS-44864") public void given_model_when_fieldRenamed_then_uselessSettersIgnored() throws Exception { EvolvedClass instance; Map<String,Object> expected = new HashMap<String, Object>(); instance = new EvolvedClass(false); expected.clear(); expected.put("option", Boolean.FALSE); assertThat("Only required properties", DescribableModel.uninstantiate2_(instance).toMap(), Matchers.is(expected)); instance = new EvolvedClass(true); expected.clear(); expected.put("option", Boolean.TRUE); assertThat("Only required properties", DescribableModel.uninstantiate2_(instance).toMap(), Matchers.is(expected)); instance = new EvolvedClass(true); instance.setName("bob"); expected.clear(); expected.put("option", Boolean.TRUE); expected.put("name", "bob"); assertThat("current setters are rendered", DescribableModel.uninstantiate2_(instance).toMap(), Matchers.is(expected)); instance = new EvolvedClass(false); instance.setTitle("bill"); expected.clear(); expected.put("option", Boolean.FALSE); expected.put("name", "bill"); assertThat("migrated setters are migrated", DescribableModel.uninstantiate2_(instance).toMap(), Matchers.is(expected)); instance = new EvolvedClass(false); instance.setName("random"); instance.setDescription("This is the thing"); expected.clear(); expected.put("option", Boolean.FALSE); expected.put("name", "random"); expected.put("description", "This is the thing"); assertThat("if the old setter mangles the value but has 1:1 mapping, we still ignore redundant setters", DescribableModel.uninstantiate2_(instance).toMap(), Matchers.is(expected)); instance = new EvolvedClass(false); instance.setName("random"); instance.setSummary("Legacy summary"); expected.clear(); expected.put("option", Boolean.FALSE); expected.put("name", "random"); expected.put("description", "Prefix: Legacy summary"); assertThat("Doesn't matter if we set the value through the old setter or the new", DescribableModel.uninstantiate2_(instance).toMap(), Matchers.is(expected)); instance = new EvolvedClass(false); instance.setLegacyMode(53); expected.clear(); expected.put("option", Boolean.FALSE); expected.put("legacyMode", 53); assertThat("A deprecated setter that produces a different object instance is retained", DescribableModel.uninstantiate2_(instance).toMap(), Matchers.is(expected)); }