public void addMixin()

in src/main/java/org/apache/sling/testing/mock/jcr/MockNode.java [533:577]


    public void addMixin(final String mixinName) throws RepositoryException {
        if (StringUtils.isNotBlank(mixinName)) {
            if(!this.hasProperty(JcrConstants.JCR_MIXINTYPES)) {
                String[] mixinNames = new String[]{mixinName};
                setProperty(JcrConstants.JCR_MIXINTYPES, mixinNames);
            } else {
                Value value = this.getSession().getValueFactory().createValue(mixinName);
                Value[] newValues = Stream.concat(
                        Arrays.stream(getProperty(JcrConstants.JCR_MIXINTYPES).getValues()),
                        Stream.of(value)
                ).toArray(Value[]::new);
                this.setProperty(JcrConstants.JCR_MIXINTYPES, newValues);
            }

            if (((MockNodeTypeManager)getSession().getWorkspace().getNodeTypeManager()).isMode(ResolveMode.ONLY_REGISTERED)) {
                NodeType mixinNodeType = getSession().getWorkspace().getNodeTypeManager().getNodeType(mixinName);
                // auto-add any autocreated children
                NodeDefinition[] childNodeDefinitions = mixinNodeType.getChildNodeDefinitions();
                for (NodeDefinition nodeDefinition : childNodeDefinitions) {
                    if (nodeDefinition.isAutoCreated()) {
                        String defaultPrimaryTypeName = nodeDefinition.getDefaultPrimaryTypeName();
                        addNode(nodeDefinition.getName(), defaultPrimaryTypeName);
                    }
                }

                // auto-add any autocreated properties
                PropertyDefinition[] propDefinitions = mixinNodeType.getPropertyDefinitions();
                for (PropertyDefinition propDefinition : propDefinitions) {
                    if (propDefinition.isAutoCreated()) {
                        Value[] defaultValues = propDefinition.getDefaultValues();
                        if (propDefinition.isMultiple()) {
                            setProperty(propDefinition.getName(), defaultValues);
                        } else if (defaultValues.length > 0) {
                            setProperty(propDefinition.getName(), defaultValues[0]);
                        } else {
                            // compute system generated property values
                            maybeSetGeneratedPropertyValue(this, propDefinition);
                        }
                    }
                }
            }
        } else {
            throw new NoSuchNodeTypeException("Not accepting blank mixin name");
        }
    }